Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
Django-Redis-Cache
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shared
Django-Redis-Cache
Commits
aa2ffa69
Commit
aa2ffa69
authored
Oct 24, 2020
by
Tomi Suomela
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decode byte keys returned by scan_iter, touch_pattern fixed
parent
230b29fe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
6 deletions
+27
-6
base.py
redis_cache/backends/base.py
+18
-6
multiple.py
redis_cache/backends/multiple.py
+5
-0
single.py
redis_cache/backends/single.py
+4
-0
No files found.
redis_cache/backends/base.py
View file @
aa2ffa69
...
...
@@ -372,7 +372,7 @@ class BaseRedisCache(BaseCache):
key_timeout
=
(
None
if
stale_cache_timeout
is
None
else
timeout
+
stale_cache_timeout
)
client
.
expire
(
"__fresh__"
+
key
,
timeout
)
client
.
expire
(
fresh_
key
,
timeout
)
return
client
.
expire
(
key
,
key_timeout
)
...
...
@@ -403,9 +403,9 @@ class BaseRedisCache(BaseCache):
def
_delete_pattern
(
self
,
client
,
pattern
):
keys
=
list
(
client
.
scan_iter
(
match
=
pattern
))
if
keys
:
all_keys
=
keys
.
copy
()
all_keys
=
[
key
.
decode
()
for
key
in
keys
]
for
key
in
keys
:
all_keys
.
append
(
"__fresh__"
+
key
)
all_keys
.
append
(
"__fresh__"
+
key
.
decode
()
)
client
.
delete
(
*
all_keys
)
def
delete_pattern
(
self
,
pattern
,
version
=
None
):
...
...
@@ -526,8 +526,20 @@ class BaseRedisCache(BaseCache):
return
acquired
@
get_client
()
def
touch_pattern
(
self
,
client
,
pattern
,
timeout
=
DEFAULT_TIMEOUT
,
stale_cache_timeout
=
None
):
def
_touch_pattern
(
self
,
client
,
pattern
,
timeout
=
DEFAULT_TIMEOUT
,
stale_cache_timeout
=
None
):
"""Reset the timeout of a keys to `timeout` seconds."""
keys
=
list
(
client
.
scan_iter
(
match
=
pattern
))
for
key
in
keys
:
self
.
touch
(
key
,
timeout
,
stale_cache_timeout
)
decoded_key
=
key
.
decode
()
key_timeout
=
timeout
fresh_key
=
"__fresh__"
+
decoded_key
if
client
.
exists
(
fresh_key
):
key_timeout
=
(
None
if
stale_cache_timeout
is
None
else
timeout
+
stale_cache_timeout
)
client
.
expire
(
fresh_key
,
timeout
)
client
.
expire
(
decoded_key
,
key_timeout
)
def
touch_pattern
(
self
,
client
,
pattern
,
timeout
=
DEFAULT_TIMEOUT
,
stale_cache_timeout
=
None
):
raise
NotImplementedError
redis_cache/backends/multiple.py
View file @
aa2ffa69
...
...
@@ -116,3 +116,8 @@ class ShardedRedisCache(BaseRedisCache):
"""
for
client
in
self
.
clients
.
values
():
self
.
_reinsert_keys
(
client
)
def
touch_pattern
(
self
,
pattern
,
timeout
=
DEFAULT_TIMEOUT
,
stale_cache_timeout
=
None
):
pattern
=
self
.
make_key
(
pattern
,
version
=
None
)
for
client
in
self
.
clients
.
values
():
self
.
_touch_pattern
(
client
,
pattern
,
timeout
,
stale_cache_timeout
)
redis_cache/backends/single.py
View file @
aa2ffa69
...
...
@@ -97,3 +97,7 @@ class RedisCache(BaseRedisCache):
Reinsert cache entries using the current pickle protocol version.
"""
self
.
_reinsert_keys
(
self
.
master_client
)
def
touch_pattern
(
self
,
pattern
,
timeout
=
DEFAULT_TIMEOUT
,
stale_cache_timeout
=
None
):
pattern
=
self
.
make_key
(
pattern
,
version
=
None
)
self
.
_touch_pattern
(
self
.
master_client
,
pattern
,
timeout
,
stale_cache_timeout
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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