Replace GenericCache with new scoped_cache

This commit is contained in:
Adrian Moennich 2021-02-03 17:03:56 +01:00
parent 593b952a91
commit c78823aa65
2 changed files with 6 additions and 6 deletions

View File

@ -10,7 +10,7 @@ from datetime import timedelta
from sqlalchemy.orm import joinedload
from indico.legacy.common.cache import GenericCache
from indico.core.cache import make_scoped_cache
from indico.modules.attachments.util import get_nested_attached_items
from indico.modules.events import Event
from indico.modules.events.contributions import Contribution
@ -54,13 +54,13 @@ class ReportBase(Serializer):
if not PiwikPlugin.settings.get('cache_enabled'):
return cls(*args, **kwargs).to_serializable()
cache = GenericCache('Piwik.Report')
cache = make_scoped_cache('piwik-report')
key = f'{cls.__name__}-{args}-{kwargs}'
report = cache.get(key)
if not report:
report = cls(*args, **kwargs)
cache.set(key, report, PiwikPlugin.settings.get('cache_ttl'))
cache.set(key, report, timeout=PiwikPlugin.settings.get('cache_ttl'))
return report.to_serializable()
def _build_report(self):

View File

@ -7,7 +7,7 @@
from zeep.cache import Base
from indico.legacy.common.cache import GenericCache
from indico.core.cache import make_scoped_cache
DEFAULT_CACHE_TTL = 24 * 3600
@ -17,11 +17,11 @@ class ZeepCache(Base):
_instance = None
def __init__(self, duration=DEFAULT_CACHE_TTL):
self._cache = GenericCache("ZeepCache")
self._cache = make_scoped_cache('zeep')
self._duration = duration
def get(self, url):
self._cache.get(url)
def add(self, url, content):
self._cache.set(url, content, self._duration)
self._cache.set(url, content, timeout=self._duration)