]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
bitbake: toaster: Add an invalidate cache method on data update signal
authorMichael Wood <michael.g.wood@intel.com>
Tue, 19 May 2015 15:10:19 +0000 (16:10 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 29 May 2015 10:59:45 +0000 (11:59 +0100)
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.

(Bitbake rev: eb0b1450e421cf65b407b1ac0336ac24ffc626e8)

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
bitbake/lib/toaster/orm/models.py
bitbake/lib/toaster/toastergui/tables.py
bitbake/lib/toaster/toastergui/widgets.py

index 0f725764d5f3e63548bbb42bf7dafe0da9d63380..fb62a55d710a1fd0ba54892d816f7d85f559d29f 100644 (file)
@@ -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)
index 78a7cb095ec253a58982df40d267feda496b13f9..9a93ff9aada52ed7db5f3c5adcad6f5dfd023dfa 100644 (file)
@@ -323,11 +323,6 @@ class LayerRecipesTable(RecipesTable):
 
 
 
-
-
-
-
-
 # This needs to be staticaly defined here as django reads the url patterns
 # on start up
 urlpatterns = (
index b5dfbbc0395b3b9e7f32435f44d5dd876c3f929a..8cf6e1bc2d4e61b4281bbbb82bb731af6e944501 100644 (file)
@@ -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