Spaces:
Runtime error
Runtime error
Commit
·
bba8925
1
Parent(s):
6547a33
cache-fix
Browse files- cache/local_cache.py +6 -4
cache/local_cache.py
CHANGED
@@ -30,12 +30,14 @@ def ttl_cache(key_name, media_type=None, ttl_secs=20):
|
|
30 |
return _cache[key]
|
31 |
|
32 |
# Call the actual function if not in cache or expired
|
33 |
-
response = await func(*args, **kwargs)
|
34 |
-
|
35 |
-
|
36 |
-
_cache[key] =
|
37 |
_cache_time[key] = datetime.now()
|
38 |
|
|
|
|
|
39 |
return response
|
40 |
|
41 |
return wrapper
|
|
|
30 |
return _cache[key]
|
31 |
|
32 |
# Call the actual function if not in cache or expired
|
33 |
+
response: StreamingResponse = await func(*args, **kwargs)
|
34 |
+
# Cache the content of the response's body.
|
35 |
+
content = await response.body.read()
|
36 |
+
_cache[key] = content
|
37 |
_cache_time[key] = datetime.now()
|
38 |
|
39 |
+
# Reset the stream to its original state so it can be consumed by the caller
|
40 |
+
response.body.seek(0)
|
41 |
return response
|
42 |
|
43 |
return wrapper
|