Beispiel #1
0
 def testCachesClear(self):
     large_image.cache_util.cache._tileCache = None
     large_image.cache_util.cache._tileLock = None
     config.setConfig('cache_backend', 'python')
     self.ExampleWithMetaclass('test')
     getTileCache()
     assert cachesInfo()['test']['used'] == 1
     cachesClear()
     assert cachesInfo()['test']['used'] == 0
Beispiel #2
0
 def testCachesInfo(self):
     large_image.cache_util.cache._tileCache = None
     large_image.cache_util.cache._tileLock = None
     assert cachesInfo()['test']['used'] == 0
     assert 'tileCache' not in cachesInfo()
     self.ExampleWithMetaclass('test')
     assert cachesInfo()['test']['used'] == 1
     config.setConfig('cache_backend', 'python')
     getTileCache()
     assert 'tileCache' in cachesInfo()
     large_image.cache_util.cache._tileCache = None
     large_image.cache_util.cache._tileLock = None
     config.setConfig('cache_backend', 'memcached')
     getTileCache()
     # memcached won't show that it is present
     assert 'tileCache' not in cachesInfo()
Beispiel #3
0
 def _tileFromHash(cls, item, x, y, z, mayRedirect=False, **kwargs):
     tileCache, tileCacheLock = getTileCache()
     if tileCache is None:
         return None
     if 'largeImage' not in item:
         return None
     if item['largeImage'].get('expected'):
         return None
     sourceName = item['largeImage']['sourceName']
     try:
         sourceClass = girder_tilesource.AvailableGirderTileSources[
             sourceName]
     except TileSourceException:
         return None
     classHash = sourceClass.getLRUHash(item, **kwargs)
     tileHash = sourceClass.__name__ + ' ' + classHash + ' ' + strhash(
         classHash) + strhash(*(x, y, z), mayRedirect=mayRedirect, **kwargs)
     try:
         if tileCacheLock is None:
             tileData = tileCache[tileHash]
         else:
             with tileCacheLock:
                 tileData = tileCache[tileHash]
         tileMime = TileOutputMimeTypes.get(kwargs.get('encoding'),
                                            'image/jpeg')
         return tileData, tileMime
     except (KeyError, ValueError):
         return None
Beispiel #4
0
 def testCachesInfo(self):
     cachesClear()
     large_image.cache_util.cache._tileCache = None
     large_image.cache_util.cache._tileLock = None
     assert cachesInfo()['test']['used'] == 0
     assert 'tileCache' not in cachesInfo()
     self.ExampleWithMetaclass('test')
     assert cachesInfo()['test']['used'] == 1
     config.setConfig('cache_backend', 'python')
     getTileCache()
     assert 'tileCache' in cachesInfo()
     large_image.cache_util.cache._tileCache = None
     large_image.cache_util.cache._tileLock = None
     config.setConfig('cache_backend', 'memcached')
     getTileCache()
     # memcached shows an items record as well
     assert 'items' in cachesInfo()['tileCache']
Beispiel #5
0
def testGetTileCacheMemcached():
    large_image.cache_util.cache._tileCache = None
    large_image.cache_util.cache._tileLock = None
    config.setConfig('cache_backend', 'memcached')
    tileCache, tileLock = getTileCache()
    assert isinstance(tileCache, MemCache)
Beispiel #6
0
def testGetTileCachePython():
    large_image.cache_util.cache._tileCache = None
    large_image.cache_util.cache._tileLock = None
    config.setConfig('cache_backend', 'python')
    tileCache, tileLock = getTileCache()
    assert isinstance(tileCache, cachetools.LRUCache)