3
3
# deepzoom_multiserver - Example web application for viewing multiple slides
4
4
#
5
5
# Copyright (c) 2010-2015 Carnegie Mellon University
6
+ # Copyright (c) 2021 Benjamin Gilbert
6
7
#
7
8
# This library is free software; you can redistribute it and/or modify it
8
9
# under the terms of version 2.1 of the GNU Lesser General Public License
43
44
else :
44
45
import openslide
45
46
46
- from openslide import OpenSlide , OpenSlideError
47
+ from openslide import OpenSlide , OpenSlideCache , OpenSlideError
47
48
from openslide .deepzoom import DeepZoomGenerator
48
49
49
50
SLIDE_DIR = '.'
50
51
SLIDE_CACHE_SIZE = 10
52
+ SLIDE_TILE_CACHE_MB = 128
51
53
DEEPZOOM_FORMAT = 'jpeg'
52
54
DEEPZOOM_TILE_SIZE = 254
53
55
DEEPZOOM_OVERLAP = 1
60
62
61
63
62
64
class _SlideCache :
63
- def __init__ (self , cache_size , dz_opts ):
65
+ def __init__ (self , cache_size , tile_cache_mb , dz_opts ):
64
66
self .cache_size = cache_size
65
67
self .dz_opts = dz_opts
66
68
self ._lock = Lock ()
67
69
self ._cache = OrderedDict ()
70
+ # Share a single tile cache among all slide handles
71
+ self ._tile_cache = OpenSlideCache (tile_cache_mb * 1024 * 1024 )
68
72
69
73
def get (self , path ):
70
74
with self ._lock :
@@ -75,6 +79,7 @@ def get(self, path):
75
79
return slide
76
80
77
81
osr = OpenSlide (path )
82
+ osr .set_cache (self ._tile_cache )
78
83
slide = DeepZoomGenerator (osr , ** self .dz_opts )
79
84
try :
80
85
mpp_x = osr .properties [openslide .PROPERTY_NAME_MPP_X ]
@@ -121,7 +126,9 @@ def _setup():
121
126
'DEEPZOOM_LIMIT_BOUNDS' : 'limit_bounds' ,
122
127
}
123
128
opts = {v : app .config [k ] for k , v in config_map .items ()}
124
- app .cache = _SlideCache (app .config ['SLIDE_CACHE_SIZE' ], opts )
129
+ app .cache = _SlideCache (
130
+ app .config ['SLIDE_CACHE_SIZE' ], app .config ['SLIDE_TILE_CACHE_MB' ], opts
131
+ )
125
132
126
133
127
134
def _get_slide (path ):
0 commit comments