##// END OF EJS Templates
caches: use .refresh() instead of .invalidate()...
marcink -
r2939:913f92bf default
parent child Browse files
Show More
@@ -161,14 +161,12 b' class RepoFeedView(RepoAppView):'
161 161 inv_context_manager = rc_cache.InvalidationContext(
162 162 uid=cache_namespace_uid, invalidation_namespace=invalidation_namespace)
163 163 with inv_context_manager as invalidation_context:
164 # check for stored invalidation signal, and maybe purge the cache
165 # before computing it again
164 args = (self.db_repo.repo_id, self.db_repo.repo_name, 'atom',)
165 # re-compute and store cache if we get invalidate signal
166 166 if invalidation_context.should_invalidate():
167 generate_atom_feed.invalidate(
168 self.db_repo.repo_id, self.db_repo.repo_name, 'atom')
169
170 mime_type, feed = generate_atom_feed(
171 self.db_repo.repo_id, self.db_repo.repo_name, 'atom')
167 mime_type, feed = generate_atom_feed.refresh(*args)
168 else:
169 mime_type, feed = generate_atom_feed(*args)
172 170
173 171 log.debug('Repo ATOM feed computed in %.3fs',
174 172 inv_context_manager.compute_time)
@@ -226,14 +224,12 b' class RepoFeedView(RepoAppView):'
226 224 inv_context_manager = rc_cache.InvalidationContext(
227 225 uid=cache_namespace_uid, invalidation_namespace=invalidation_namespace)
228 226 with inv_context_manager as invalidation_context:
229 # check for stored invalidation signal, and maybe purge the cache
230 # before computing it again
227 args = (self.db_repo.repo_id, self.db_repo.repo_name, 'rss',)
228 # re-compute and store cache if we get invalidate signal
231 229 if invalidation_context.should_invalidate():
232 generate_rss_feed.invalidate(
233 self.db_repo.repo_id, self.db_repo.repo_name, 'rss')
234
235 mime_type, feed = generate_rss_feed(
236 self.db_repo.repo_id, self.db_repo.repo_name, 'rss')
230 mime_type, feed = generate_rss_feed.refresh(*args)
231 else:
232 mime_type, feed = generate_rss_feed(*args)
237 233 log.debug(
238 234 'Repo RSS feed computed in %.3fs', inv_context_manager.compute_time)
239 235
@@ -88,14 +88,12 b' class RepoSummaryView(RepoAppView):'
88 88 inv_context_manager = rc_cache.InvalidationContext(
89 89 uid=cache_namespace_uid, invalidation_namespace=invalidation_namespace)
90 90 with inv_context_manager as invalidation_context:
91 # check for stored invalidation signal, and maybe purge the cache
92 # before computing it again
91 args = (db_repo.repo_id, db_repo.repo_name, renderer_type,)
92 # re-compute and store cache if we get invalidate signal
93 93 if invalidation_context.should_invalidate():
94 generate_repo_readme.invalidate(
95 db_repo.repo_id, db_repo.repo_name, renderer_type)
96
97 instance = generate_repo_readme(
98 db_repo.repo_id, db_repo.repo_name, renderer_type)
94 instance = generate_repo_readme.refresh(*args)
95 else:
96 instance = generate_repo_readme(*args)
99 97
100 98 log.debug(
101 99 'Repo readme generated and computed in %.3fs',
@@ -227,14 +227,15 b' class InvalidationContext(object):'
227 227 inv_context_manager = rc_cache.InvalidationContext(
228 228 uid=cache_namespace_uid, invalidation_namespace=invalidation_namespace)
229 229 with inv_context_manager as invalidation_context:
230 # check for stored invalidation signal, and maybe purge the cache
231 # before computing it again
230 args = ('one', 'two')
231 # re-compute and store cache if we get invalidate signal
232 232 if invalidation_context.should_invalidate():
233 heavy_compute.invalidate('some_name', 'param1', 'param2')
233 result = heavy_compute.refresh(*args)
234 else:
235 result = heavy_compute(*args)
234 236
235 result = heavy_compute('some_name', 'param1', 'param2')
236 237 compute_time = inv_context_manager.compute_time
237 print(compute_time)
238 log.debug('result computed in %.3fs' ,compute_time)
238 239
239 240 # To send global invalidation signal, simply run
240 241 CacheKey.set_invalidate(invalidation_namespace)
@@ -2342,12 +2342,13 b' class Repository(Base, BaseModel):'
2342 2342 inv_context_manager = rc_cache.InvalidationContext(
2343 2343 uid=cache_namespace_uid, invalidation_namespace=invalidation_namespace)
2344 2344 with inv_context_manager as invalidation_context:
2345 # check for stored invalidation signal, and maybe purge the cache
2346 # before computing it again
2345 args = (self.repo_id,)
2346 # re-compute and store cache if we get invalidate signal
2347 2347 if invalidation_context.should_invalidate():
2348 get_instance_cached.invalidate(self.repo_id)
2349
2350 instance = get_instance_cached(self.repo_id)
2348 instance = get_instance_cached.refresh(*args)
2349 else:
2350 instance = get_instance_cached(*args)
2351
2351 2352 log.debug(
2352 2353 'Repo instance fetched in %.3fs', inv_context_manager.compute_time)
2353 2354 return instance
@@ -583,7 +583,8 b' def test_invalidation_context(baseapp):'
583 583 with inv_context_manager as invalidation_context:
584 584 should_invalidate = invalidation_context.should_invalidate()
585 585 if should_invalidate:
586 _dummy_func.invalidate('some-key')
586 result = _dummy_func.refresh('some-key')
587 else:
587 588 result = _dummy_func('some-key')
588 589
589 590 assert isinstance(invalidation_context, rc_cache.FreshRegionCache)
@@ -608,7 +609,8 b' def test_invalidation_context(baseapp):'
608 609 with inv_context_manager as invalidation_context:
609 610 should_invalidate = invalidation_context.should_invalidate()
610 611 if should_invalidate:
611 _dummy_func.invalidate('some-key')
612 result = _dummy_func.refresh('some-key')
613 else:
612 614 result = _dummy_func('some-key')
613 615
614 616 assert isinstance(invalidation_context, rc_cache.FreshRegionCache)
@@ -642,7 +644,8 b' def test_invalidation_context_exception_'
642 644 with inv_context_manager as invalidation_context:
643 645 should_invalidate = invalidation_context.should_invalidate()
644 646 if should_invalidate:
645 _dummy_func.invalidate('some-key-2')
647 _dummy_func.refresh('some-key-2')
648 else:
646 649 _dummy_func('some-key-2')
647 650
648 651
@@ -674,7 +677,8 b' def test_cache_invalidation_race_conditi'
674 677 with inv_context_manager as invalidation_context:
675 678 should_invalidate = invalidation_context.should_invalidate()
676 679 if should_invalidate:
677 _dummy_func.invalidate('some-key-3')
680 _dummy_func.refresh('some-key-3')
681 else:
678 682 _dummy_func('some-key-3')
679 683
680 684 # Mark invalidation
General Comments 0
You need to be logged in to leave comments. Login now