[bitbake-devel] [PATCH 10/22] toaster: Add an invalidate cache method on data update signal

Alex DAMIAN alexandru.damian at intel.com
Thu May 28 14:14:04 UTC 2015


From: Michael Wood <michael.g.wood at intel.com>

Instead of relying on the cache expiring over an amount of time we can
listen to the changed notification on the models to invalidate the
cache. Also fixes overlapping cache names.

Signed-off-by: Michael Wood <michael.g.wood at intel.com>
---
 lib/toaster/orm/models.py         | 12 ++++++++++++
 lib/toaster/toastergui/tables.py  |  5 -----
 lib/toaster/toastergui/widgets.py |  6 ++++--
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/lib/toaster/orm/models.py b/lib/toaster/orm/models.py
index 0f72576..fb62a55 100644
--- a/lib/toaster/orm/models.py
+++ b/lib/toaster/orm/models.py
@@ -26,6 +26,7 @@ from django.utils import timezone
 
 from django.core import validators
 from django.conf import settings
+import django.db.models.signals
 
 class GitURLValidator(validators.URLValidator):
     import re
@@ -1176,3 +1177,14 @@ class LogMessage(models.Model):
     message=models.CharField(max_length=240)
     pathname = models.FilePathField(max_length=255, blank=True)
     lineno = models.IntegerField(null=True)
+
+def invalidate_cache(**kwargs):
+    from django.core.cache import cache
+    try:
+      cache.clear()
+    except Exception as e:
+      print "Problem with cache backend: Failed to clear cache"
+      pass
+
+django.db.models.signals.post_save.connect(invalidate_cache)
+django.db.models.signals.post_delete.connect(invalidate_cache)
diff --git a/lib/toaster/toastergui/tables.py b/lib/toaster/toastergui/tables.py
index 78a7cb0..9a93ff9 100644
--- a/lib/toaster/toastergui/tables.py
+++ b/lib/toaster/toastergui/tables.py
@@ -323,11 +323,6 @@ class LayerRecipesTable(RecipesTable):
 
 
 
-
-
-
-
-
 # This needs to be staticaly defined here as django reads the url patterns
 # on start up
 urlpatterns = (
diff --git a/lib/toaster/toastergui/widgets.py b/lib/toaster/toastergui/widgets.py
index b5dfbbc..8cf6e1b 100644
--- a/lib/toaster/toastergui/widgets.py
+++ b/lib/toaster/toastergui/widgets.py
@@ -245,6 +245,9 @@ class ToasterTable(View):
         for key, val in request.GET.iteritems():
             cache_name = cache_name + str(key) + str(val)
 
+        for key, val in kwargs.iteritems():
+            cache_name = cache_name + str(key) + str(val)
+
         data = cache.get(cache_name)
 
         if data:
@@ -306,8 +309,7 @@ class ToasterTable(View):
         except FieldError:
             print "Error: Requested field does not exist"
 
-
         data = json.dumps(data, indent=2, cls=DjangoJSONEncoder)
-        cache.set(cache_name, data, 10)
+        cache.set(cache_name, data, 60*30)
 
         return data
-- 
1.9.1




More information about the bitbake-devel mailing list