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
8ee175f5
Commit
8ee175f5
authored
Jun 17, 2010
by
sebleier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made it possible to have non-expiring keys
Thanks to Kami for the report and Jezdez for being awesome.
parent
5a8ab033
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
3 deletions
+50
-3
cache.py
redis_cache/cache.py
+11
-3
tests.py
tests/testapp/tests.py
+39
-0
No files found.
redis_cache/cache.py
View file @
8ee175f5
...
@@ -85,9 +85,17 @@ class CacheClass(BaseCache):
...
@@ -85,9 +85,17 @@ class CacheClass(BaseCache):
"""
"""
Set content expiration, if necessary
Set content expiration, if necessary
"""
"""
if
timeout
is
None
:
if
timeout
==
0
:
timeout
=
self
.
default_timeout
# force the key to be non-volatile
self
.
_cache
.
expire
(
key
,
timeout
)
result
=
self
.
_cache
.
get
(
key
)
self
.
_cache
.
set
(
key
,
result
)
else
:
timeout
=
timeout
or
self
.
default_timeout
# If the expiration command returns false, we need to reset the key
# with the new expiration
if
not
self
.
_cache
.
expire
(
key
,
timeout
):
value
=
self
.
get
(
key
)
self
.
set
(
key
,
value
,
timeout
)
def
delete
(
self
,
key
):
def
delete
(
self
,
key
):
"""
"""
...
...
tests/testapp/tests.py
View file @
8ee175f5
...
@@ -3,6 +3,11 @@
...
@@ -3,6 +3,11 @@
import
time
import
time
import
unittest
import
unittest
try
:
import
cPickle
as
pickle
except
ImportError
:
import
pickle
from
django.core.cache
import
get_cache
from
django.core.cache
import
get_cache
from
models
import
Poll
,
expensive_calculation
from
models
import
Poll
,
expensive_calculation
...
@@ -160,6 +165,40 @@ class RedisCacheTests(unittest.TestCase):
...
@@ -160,6 +165,40 @@ class RedisCacheTests(unittest.TestCase):
self
.
assertEqual
(
self
.
cache
.
get
(
"expire2"
),
"newvalue"
)
self
.
assertEqual
(
self
.
cache
.
get
(
"expire2"
),
"newvalue"
)
self
.
assertEqual
(
self
.
cache
.
has_key
(
"expire3"
),
False
)
self
.
assertEqual
(
self
.
cache
.
has_key
(
"expire3"
),
False
)
def
test_set_expiration_timeout_None
(
self
):
key
,
value
=
'key'
,
'value'
self
.
cache
.
set
(
key
,
value
);
self
.
assertTrue
(
self
.
cache
.
_cache
.
ttl
(
key
)
>
0
)
def
test_set_expiration_timeout_0
(
self
):
key
,
value
=
'key'
,
'value'
self
.
cache
.
set
(
key
,
value
);
self
.
assertTrue
(
self
.
cache
.
_cache
.
ttl
(
key
)
>
0
)
self
.
cache
.
expire
(
key
,
0
)
self
.
assertEqual
(
self
.
cache
.
get
(
key
),
value
)
self
.
assertTrue
(
self
.
cache
.
_cache
.
ttl
(
key
)
<
0
)
def
test_set_expiration_first_expire_call
(
self
):
key
,
value
=
self
.
cache
.
prepare_key
(
'key'
),
'value'
# bypass public set api so we don't set the expiration
self
.
cache
.
_cache
.
set
(
key
,
pickle
.
dumps
(
value
))
self
.
cache
.
expire
(
key
,
1
)
time
.
sleep
(
2
)
self
.
assertEqual
(
self
.
cache
.
get
(
'key'
),
None
)
def
test_set_expiration_mulitple_expire_calls
(
self
):
key
,
value
=
'key'
,
'value'
self
.
cache
.
set
(
key
,
value
,
1
)
time
.
sleep
(
2
)
self
.
assertEqual
(
self
.
cache
.
get
(
'key'
),
None
)
self
.
cache
.
set
(
key
,
value
,
100
)
self
.
assertEqual
(
self
.
cache
.
get
(
'key'
),
value
)
time
.
sleep
(
2
)
self
.
assertEqual
(
self
.
cache
.
get
(
'key'
),
value
)
self
.
cache
.
expire
(
key
,
1
)
time
.
sleep
(
2
)
self
.
assertEqual
(
self
.
cache
.
get
(
'key'
),
None
)
def
test_unicode
(
self
):
def
test_unicode
(
self
):
# Unicode values can be cached
# Unicode values can be cached
stuff
=
{
stuff
=
{
...
...
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