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