changeset 7944:d6a56c5a77fc

caching: invalidate Repository cache of README and RSS based on latest revision hash in its .changeset_cache Avoid using the the more heavy and complex CacheInvalidation. Note that raw_id only is passed to the getter function as cache key, in order to make sure new data is retrieved whenever the repo changes.
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 21 Oct 2019 00:17:28 +0200
parents 6fe3d405ff48
children f626260a376c
files kallithea/controllers/feed.py kallithea/controllers/summary.py
diffstat 2 files changed, 6 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/feed.py	Thu Nov 14 22:58:55 2019 +0100
+++ b/kallithea/controllers/feed.py	Mon Oct 21 00:17:28 2019 +0200
@@ -28,7 +28,7 @@
 
 import logging
 
-from beaker.cache import cache_region, region_invalidate
+from beaker.cache import cache_region
 from tg import response
 from tg import tmpl_context as c
 from tg.i18n import ugettext as _
@@ -40,7 +40,6 @@
 from kallithea.lib.base import BaseRepoController
 from kallithea.lib.diffs import DiffProcessor
 from kallithea.lib.utils2 import safe_int, safe_unicode, str2bool
-from kallithea.model.db import CacheInvalidation
 
 
 log = logging.getLogger(__name__)
@@ -130,10 +129,7 @@
             return feed.writeString('utf-8')
 
         kind = 'ATOM'
-        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
-        if not valid:
-            region_invalidate(_get_feed_from_cache, None, '_get_feed_from_cache', repo_name, kind)
-        return _get_feed_from_cache(repo_name, kind)
+        return _get_feed_from_cache(repo_name, kind, c.db_repo.changeset_cache.get('raw_id'))
 
     def rss(self, repo_name):
         """Produce an rss2 feed via feedgenerator module"""
@@ -162,7 +158,4 @@
             return feed.writeString('utf-8')
 
         kind = 'RSS'
-        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
-        if not valid:
-            region_invalidate(_get_feed_from_cache, None, '_get_feed_from_cache', repo_name, kind)
-        return _get_feed_from_cache(repo_name, kind)
+        return _get_feed_from_cache(repo_name, kind, c.db_repo.changeset_cache.get('raw_id'))
--- a/kallithea/controllers/summary.py	Thu Nov 14 22:58:55 2019 +0100
+++ b/kallithea/controllers/summary.py	Mon Oct 21 00:17:28 2019 +0200
@@ -32,7 +32,7 @@
 from datetime import date, timedelta
 from time import mktime
 
-from beaker.cache import cache_region, region_invalidate
+from beaker.cache import cache_region
 from tg import request
 from tg import tmpl_context as c
 from tg.i18n import ugettext as _
@@ -49,7 +49,7 @@
 from kallithea.lib.vcs.backends.base import EmptyChangeset
 from kallithea.lib.vcs.exceptions import ChangesetError, EmptyRepositoryError, NodeDoesNotExistError
 from kallithea.lib.vcs.nodes import FileNode
-from kallithea.model.db import CacheInvalidation, Statistics
+from kallithea.model.db import Statistics
 
 
 log = logging.getLogger(__name__)
@@ -97,10 +97,7 @@
             return readme_data, readme_file
 
         kind = 'README'
-        valid = CacheInvalidation.test_and_set_valid(repo_name, kind)
-        if not valid:
-            region_invalidate(_get_readme_from_cache, None, '_get_readme_from_cache', repo_name, kind)
-        return _get_readme_from_cache(repo_name, kind)
+        return _get_readme_from_cache(repo_name, kind, c.db_repo.changeset_cache.get('raw_id'))
 
     @LoginRequired(allow_default_user=True)
     @HasRepoPermissionLevelDecorator('read')