Skip to content

Commit

Permalink
Only do more aggressive caching for nuxeo content
Browse files Browse the repository at this point in the history
  • Loading branch information
amywieliczka committed Oct 18, 2024
1 parent 60adcc8 commit 70ca8f3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions content_harvester/by_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,23 @@ def check_component_cache(
# Do a head request to get the current ETag and
# Last-Modified values, used to create a cache key
head_resp = http_session.head(**asdict(request))
cache_key = ''
if not (
head_resp.headers.get('ETag') or
head_resp.headers.get('Last-Modified')
):
print(
f"{component_type}: No ETag or Last-Modified headers, "
"checking cache and judging cache hit based on URL and "
"date since content component creation"
"checking if nuxeo in request url, and if so, trying "
"a cache key without ETag or Last-Modified"
)
# Create cache key without ETag or Last-Modified
cache_key = '/'.join([
str(collection_id),
quote_plus(request.url),
component_type
])
if 'nuxeo' in request.url:
# Create cache key without ETag or Last-Modified
cache_key = '/'.join([
str(collection_id),
quote_plus(request.url),
component_type
])
else:
# Create specific cache key
cache_key = '/'.join([
Expand Down Expand Up @@ -294,9 +296,8 @@ def check_component_cache(
collection_id, request, *args, **kwargs)
print(f"Created {component_type} component for {request.url}")
# set cache key to the component
persistent_cache[cache_key] = component
if component:
if component['path'] is not None:
if cache_key and component['path'] is not None:
persistent_cache[cache_key] = component
return {**component, 'from-cache': False}, tmp_files
else:
Expand Down

0 comments on commit 70ca8f3

Please sign in to comment.