Skip to content

Commit

Permalink
openaire: fix image cache and related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiaraBi committed Feb 8, 2019
1 parent 7701a08 commit dc395a8
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 68 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ invenio-files-rest==1.0.0a23
invenio-formatter==1.0.0
invenio-github==1.0.0a15
invenio-i18n==1.0.0
invenio-iiif==1.0.0a4
invenio-iiif==1.0.0a5
invenio-indexer==1.0.1
invenio-jsonschemas==1.0.0
invenio-logging==1.0.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
'invenio-formatter>=1.0.0',
'invenio-github>=1.0.0a15',
'invenio-i18n>=1.0.0',
'invenio-iiif>=1.0.0a4',
'invenio-iiif>=1.0.0a5',
'invenio-indexer>=1.0.1',
'invenio-jsonschemas>=1.0.0',
'invenio-logging>=1.0.0',
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
from zenodo.modules.deposit.minters import zenodo_deposit_minter
from zenodo.modules.fixtures.records import loadsipmetadatatypes
from zenodo.modules.github.cli import github
from zenodo.modules.iiif.cache import FilteredImageRedisCache
from zenodo.modules.records.api import ZenodoRecord
from zenodo.modules.records.models import AccessRight
from zenodo.modules.records.serializers.bibtex import Bibtex
from zenodo.modules.thumbnails.cache import ImageRedisCache


@pytest.yield_fixture(scope='session')
Expand Down Expand Up @@ -1134,10 +1134,11 @@ def g_tester_id(app, db):


@pytest.fixture
def iiif_cache():
def iiif_cache(app):
"""Fixture for iiif chache."""
cache = ImageRedisCache()
cache = app.extensions['iiif'].cache()
yield cache
iiif_keys = [k for k in cache.cache._client.keys() if k.find("iiif:") != -1]
iiif_keys = [k.decode() for k in cache.cache._client.keys()
if k.decode().startswith(u"iiif:")]
for key in iiif_keys:
cache.delete(key)
4 changes: 2 additions & 2 deletions tests/unit/iiif/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

def test_thumbnail_caching(app, iiif_cache):
"""Test thumbnail cache."""
key_250 = 'iiif:identifier1/full/250,/0/default.png'
key = 'iiif:identifier2/full/260,/0/default.jpg'
key_250 = 'iiif:identifier1/full/250,/default/0.png'
key = 'iiif:identifier2/full/260,/default/0.jpg'
value = 'value'

# only images with size == (250,) are cached
Expand Down
2 changes: 1 addition & 1 deletion zenodo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ def _(x):
IIIF_RESIZE_RESAMPLE = 'PIL.Image:BICUBIC'

#: IIIF Cache handler
IIIF_CACHE_HANDLER = 'zenodo.modules.thumbnails.cache:ImageRedisCache'
IIIF_CACHE_HANDLER = 'zenodo.modules.iiif.cache:FilteredImageRedisCache'

# Redis URL Cache
IIIF_CACHE_REDIS_URL = CACHE_REDIS_URL
Expand Down
15 changes: 8 additions & 7 deletions zenodo/modules/iiif/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

from __future__ import absolute_import

from flask_iiif.cache.redis import ImageRedisCache as ImageCache
from flask_iiif.cache.redis import ImageRedisCache


class ImageRedisCache(ImageCache):
class FilteredImageRedisCache(ImageRedisCache):
"""Redis image cache."""

def __init__(self):
"""Initialize the cache."""
super(ImageRedisCache, self).__init__()
super(FilteredImageRedisCache, self).__init__()

def set(self, key, value, timeout=None):
"""Cache the object.
Expand All @@ -44,7 +44,8 @@ def set(self, key, value, timeout=None):
:type value: `BytesIO` object
:param timeout: the cache timeout in seconds
"""
identifier, _, size, _, _ = key.split('/')
if size == '250,':
timeout = timeout if timeout else self.timeout
self.cache.set(key, value, timeout=timeout)
identifier, region, size, quality, rotation_format = key.split('/')
if size == '250,' and region == 'full' and quality == 'default' and \
rotation_format.startswith(u'0.'):
timeout = timeout if timeout else self.timeout
self.cache.set(key, value, timeout=timeout)
52 changes: 0 additions & 52 deletions zenodo/modules/thumbnails/cache.py

This file was deleted.

0 comments on commit dc395a8

Please sign in to comment.