commit ca6bb3d50a1fa203666185fbfdf896d708e3ab7e
Author: Leonidas Poulopoulos <leopoul@noc.grnet.gr>
Date:   Fri Dec 9 19:46:37 2011 +0200

    Fixed cache issues. Fixed a major long-polling issue with a keepalive function

diff --git a/templates/poller.js b/templates/poller.js
index 970e28e..108864c 100644
--- a/templates/poller.js
+++ b/templates/poller.js
@@ -11,7 +11,7 @@
 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 // License for the specific language governing permissions and limitations
 // under the License.
-
+var xhrlp = '';
 $(document).ready(function() {
     if (!window.console) window.console = {};
     if (!window.console.log) window.console.log = function() {};
@@ -29,10 +29,13 @@ $(document).ready(function() {
     $("#message").select();
     {% if user.is_authenticated %}
     updater.start();
-    updater.poll();
+    updater.keepalive();
+    
     {% endif %}
 });
 
+
+
 function newMessage(form) {
     var message = form.formToDict();
     var disabled = form.find("input[type=submit]");
@@ -89,21 +92,39 @@ jQuery.fn.enable = function(opt_enable) {
 var updater = {
     errorSleepTime: 500,
     cursor: null,
+    xhrlp: null,
+    
+    keepalive: function (){
+	try {
+		updater.xhrlp.abort();
+	}
+	catch (e) {	 
+	}
+	updater.poll();
+	if (updater.errorSleepTime == 500){
+		window.setTimeout(updater.keepalive, 180000);
+	}
+//	if (updater.errorSleepTime > 60000){
+//		window.setTimeout('location.reload()', 3000);
+//		}
+	},
     
     start: function() {
-    	$.ajax({url: "{% url fetch-existing %}", type: "POST", dataType: "text",
+		$.ajax({url: "{% url fetch-existing %}", type: "POST", dataType: "text",
     		success: updater.onFetchExisting,
     		error: updater.onError});
         },
     
     poll: function() {
-	{% if user.is_authenticated %}
-	$.ajax({url: "{% url fetch-updates %}", type: "POST", dataType: "text",
-		success: updater.onSuccess,
-		error: updater.onError});
-	{% endif %}
+    	{% if user.is_authenticated %}
+    	if (updater.errorSleepTime > 60000){
+    		window.setTimeout('location.reload()', 1000);
+    		}
+    	updater.xhrlp=$.ajax({url: "{% url fetch-updates %}", type: "POST", dataType: "text",
+    		success: updater.onSuccess,
+    		error: updater.onError});
+    	{% endif %}
     },
-
     onSuccess: function(response) {
 	try {
 	    updater.newMessages(eval("(" + response + ")"));
@@ -124,10 +145,12 @@ var updater = {
     	}
         },
      
-    onError: function(response) {
-	updater.errorSleepTime *= 2;
-	console.log("Poll error; sleeping for", updater.errorSleepTime, "ms");
-	window.setTimeout(updater.poll, updater.errorSleepTime);
+    onError: function(response, text) {
+        	if (text != 'abort'){
+				updater.errorSleepTime *= 2;
+				console.log("Poll error; sleeping for", updater.errorSleepTime, "ms");
+				window.setTimeout(updater.keepalive, updater.errorSleepTime);
+        	}
     },
 
     newMessages: function(response) {
diff --git a/utils/proxy.py b/utils/proxy.py
index c894504..eb84f0c 100644
--- a/utils/proxy.py
+++ b/utils/proxy.py
@@ -38,12 +38,14 @@ class Retriever(object):
     
     def fetch_device(self):
         device = cache.get("device")
+        logger.info("[CACHE] hit! got device")
         if device:
             return device
         else:
             device = self.proccess_xml()
             if device.routing_options:
-                cache.set("device", device)
+                cache.set("device", device, 3600)
+                logger.info("[CACHE] miss, setting device")
                 return device
             else:
                 return False
@@ -188,7 +190,8 @@ class Applier(object):
                                     logger.info("Successfully committed @ %s" % self.device)
                                     newconfig = m.get_config(source='running', filter=('subtree',settings.ROUTES_FILTER)).data_xml
                                     retrieve = Retriever(xml=newconfig)
-                                    cache.set("device", retrieve.proccess_xml())
+                                    logger.info("[CACHE] caching device configuration")
+                                    cache.set("device", retrieve.proccess_xml(), 3600)
                                     
                                     if not commit_is_successful:
                                         raise Exception()
