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
32 lines (24 loc) · 974 Bytes
/
Copy pathcache.py
File metadata and controls
32 lines (24 loc) · 974 Bytes
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
from pulpcore.plugin.cache import CacheKeys, SyncContentCache
from pulpcore.plugin.util import cache_key
ACCEPT_HEADER_KEY = "accept_header"
class PythonApiCache(SyncContentCache):
"""
Cache for the Simple API.
Adds Accept header to the cache key so HTML and JSON responses are cached separately.
"""
def __init__(self, base_key=None):
keys = (CacheKeys.path, CacheKeys.method, ACCEPT_HEADER_KEY)
super().__init__(base_key=base_key, keys=keys)
def make_key(self, request):
all_keys = {
CacheKeys.path: request.path,
CacheKeys.method: request.method,
ACCEPT_HEADER_KEY: request.headers.get("accept", ""),
}
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)