Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Darck Crystale
api
Commits
507fa328
Verified
Commit
507fa328
authored
Jul 01, 2019
by
Eliot Berriot
Browse files
Implement proper cache busting
parent
124aca7b
Changes
4
Hide whitespace changes
Inline
Side-by-side
retribute_api/cache.py
View file @
507fa328
...
...
@@ -46,9 +46,10 @@ class Noop(Backend):
class
Redis
(
Backend
):
def
__init__
(
self
,
params
):
def
__init__
(
self
,
params
,
write_only
=
False
):
self
.
params
=
params
self
.
_redis
=
None
self
.
write_only
=
write_only
async
def
redis
(
self
):
if
self
.
_redis
:
...
...
@@ -59,6 +60,8 @@ class Redis(Backend):
return
self
.
_redis
async
def
get
(
self
,
key
):
if
self
.
write_only
:
raise
self
.
NotFound
(
key
)
r
=
await
self
.
redis
()
try
:
v
=
await
r
.
get
(
key
)
...
...
@@ -89,9 +92,20 @@ class Redis(Backend):
_DEFAULT
=
None
def
get_default
():
_WRITE_ONLY_DEFAULT
=
None
def
get_write_only_default
():
global
_WRITE_ONLY_DEFAULT
if
_WRITE_ONLY_DEFAULT
:
return
_WRITE_ONLY_DEFAULT
_WRITE_ONLY_DEFAULT
=
Redis
(
settings
.
ASYNC_REDIS_PARAMS
,
write_only
=
True
)
return
_WRITE_ONLY_DEFAULT
def
get_default
(
**
kwargs
):
global
_DEFAULT
if
_DEFAULT
:
return
_DEFAULT
_DEFAULT
=
Redis
(
settings
.
ASYNC_REDIS_PARAMS
)
_DEFAULT
=
Redis
(
settings
.
ASYNC_REDIS_PARAMS
,
**
kwargs
)
return
_DEFAULT
retribute_api/search/consumers.py
View file @
507fa328
...
...
@@ -98,7 +98,7 @@ class SearchSingleConsumer(AsyncHttpConsumer):
self
.
scope
[
"query_string"
].
decode
(),
keep_blank_values
=
True
)
if
"nocache"
in
params
:
c
=
cache
.
Noop
()
c
=
cache
.
get_write_only_default
()
else
:
c
=
cache
.
get_default
()
try
:
...
...
retribute_api/search/sources.py
View file @
507fa328
...
...
@@ -44,7 +44,6 @@ class Activitypub(Source):
]
async
def
get
(
self
,
lookup
,
session
,
cache
):
try
:
actor_data
=
await
cache
.
get
(
"activitypub:profile:{}"
.
format
(
lookup
))
except
cache
.
NotFound
:
...
...
tests/search/test_consumers.py
View file @
507fa328
...
...
@@ -72,7 +72,7 @@ async def test_search_consumer_no_cache(
)
response
=
await
communicator
.
get_response
()
assert
get
.
call_args
[
0
][
0
]
==
"test@user.domain"
assert
isinstance
(
get
.
call_args
[
1
][
"cache"
]
,
cache
.
Noop
)
assert
get
.
call_args
[
1
][
"cache"
]
.
write_only
is
True
get_profile
.
assert_called_once_with
(
"webfinger"
,
"test@user.domain"
,
get
.
return_value
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment