changeset 3757:f08881dcc9eb beta

invalidate: clear CacheInvalidation when upgrading
author Mads Kiilerich <madski@unity3d.com>
date Wed, 03 Apr 2013 15:56:12 +0200
parents 8beaaea70a89
children d5c684052ea4
files rhodecode/lib/db_manage.py rhodecode/model/db.py
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/db_manage.py	Fri Apr 05 00:40:58 2013 +0200
+++ b/rhodecode/lib/db_manage.py	Wed Apr 03 15:56:12 2013 +0200
@@ -37,7 +37,7 @@
 from rhodecode.model import init_model
 from rhodecode.model.db import User, Permission, RhodeCodeUi, \
     RhodeCodeSetting, UserToPerm, DbMigrateVersion, RepoGroup, \
-    UserRepoGroupToPerm
+    UserRepoGroupToPerm, CacheInvalidation
 
 from sqlalchemy.engine import create_engine
 from rhodecode.model.repos_group import ReposGroupModel
@@ -150,6 +150,10 @@
         if curr_version == __dbversion__:
             sys.exit('This database is already at the newest version')
 
+        # clear cache keys
+        log.info("Clearing cache keys now...")
+        CacheInvalidation.clear_cache()
+
         #======================================================================
         # UPGRADE STEPS
         #======================================================================
--- a/rhodecode/model/db.py	Fri Apr 05 00:40:58 2013 +0200
+++ b/rhodecode/model/db.py	Wed Apr 03 15:56:12 2013 +0200
@@ -1806,6 +1806,15 @@
         return self._cache_key_partition()[2]
 
     @classmethod
+    def clear_cache(cls):
+        """
+        Delete all cache keys from database.
+        Should only be run when all instances are down and all entries thus stale.
+        """
+        cls.query().delete()
+        Session().commit()
+
+    @classmethod
     def _get_cache_key(cls, key):
         """
         Wrapper for generating a unique cache key for this instance and "key".