forked from pulp/pulp_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.py
More file actions
33 lines (25 loc) · 1.01 KB
/
Copy pathcache.py
File metadata and controls
33 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from pulpcore.plugin.cache import CacheKeys, SyncContentCache
from pulpcore.plugin.util import cache_key
MEDIA_TYPE_KEY = "media_type"
class PythonApiCache(SyncContentCache):
"""
Cache for the Simple API.
Keys on the negotiated media type so HTML and JSON are cached separately,
including when the same Accept header is used with `?format=json`.
"""
def __init__(self, base_key=None):
keys = (CacheKeys.path, CacheKeys.method, MEDIA_TYPE_KEY)
super().__init__(base_key=base_key, keys=keys)
def make_key(self, request):
all_keys = {
CacheKeys.path: request.path,
CacheKeys.method: request.method,
MEDIA_TYPE_KEY: getattr(request, "accepted_media_type", "") or "",
}
return ":".join(all_keys[k] for k in self.keys)
def find_base_path_cached(request, cached):
"""
Resolve the distribution base_path for use as the Redis cache base_key.
"""
path = request.resolver_match.kwargs["path"]
return cache_key(path)