44
44
from .log import log_request
45
45
from .utils import git_info , jupyter_info , url_path_join
46
46
47
+ try : # Python 3.8
48
+ from functools import cached_property
49
+ except ImportError :
50
+ from .utils import cached_property
51
+
47
52
#-----------------------------------------------------------------------------
48
53
# Code
49
54
#-----------------------------------------------------------------------------
@@ -115,13 +120,13 @@ def _load_max_cache_uris(self):
115
120
def _load_static_url_prefix (self ):
116
121
return url_path_join (self .base_url , '/static/' )
117
122
118
- @property
123
+ @cached_property
119
124
def base_url (self ):
120
125
# prefer the JupyterHub defined service prefix over the CLI
121
126
base_url = os .getenv ("JUPYTERHUB_SERVICE_PREFIX" , options .base_url )
122
127
return base_url
123
128
124
- @property
129
+ @cached_property
125
130
def cache (self ):
126
131
memcache_urls = os .environ .get ('MEMCACHIER_SERVERS' , os .environ .get ('MEMCACHE_SERVERS' ))
127
132
# Handle linked Docker containers
@@ -154,14 +159,14 @@ def cache(self):
154
159
155
160
# for some reason this needs to be a computed property,
156
161
# and not a traitlets Any(), otherwise nbviewer won't run
157
- @property
162
+ @cached_property
158
163
def client (self ):
159
164
AsyncHTTPClient .configure (HTTPClientClass )
160
165
client = AsyncHTTPClient ()
161
166
client .cache = self .cache
162
167
return client
163
168
164
- @property
169
+ @cached_property
165
170
def env (self ):
166
171
env = Environment (loader = FileSystemLoader (self .template_paths ), autoescape = True )
167
172
env .filters ['markdown' ] = markdown .markdown
@@ -180,7 +185,7 @@ def env(self):
180
185
181
186
return env
182
187
183
- @property
188
+ @cached_property
184
189
def fetch_kwargs (self ):
185
190
fetch_kwargs = dict (connect_timeout = 10 ,)
186
191
if options .proxy_host :
@@ -194,13 +199,13 @@ def fetch_kwargs(self):
194
199
195
200
return fetch_kwargs
196
201
197
- @property
202
+ @cached_property
198
203
def formats (self ):
199
204
formats = configure_formats (options , self .config , log .app_log )
200
205
return formats
201
206
202
207
# load frontpage sections
203
- @property
208
+ @cached_property
204
209
def frontpage_setup (self ):
205
210
with io .open (options .frontpage , 'r' ) as f :
206
211
frontpage_setup = json .load (f )
@@ -213,20 +218,20 @@ def frontpage_setup(self):
213
218
}
214
219
return frontpage_setup
215
220
216
- @property
221
+ @cached_property
217
222
def pool (self ):
218
223
if options .processes :
219
224
pool = ProcessPoolExecutor (options .processes )
220
225
else :
221
226
pool = ThreadPoolExecutor (options .threads )
222
227
return pool
223
228
224
- @property
229
+ @cached_property
225
230
def rate_limiter (self ):
226
231
rate_limiter = RateLimiter (limit = options .rate_limit , interval = options .rate_limit_interval , cache = self .cache )
227
232
return rate_limiter
228
233
229
- @property
234
+ @cached_property
230
235
def template_paths (self ):
231
236
template_paths = pjoin (here , 'templates' )
232
237
if options .template_path is not None :
0 commit comments