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
c2ccc74a
Commit
c2ccc74a
authored
Jan 04, 2014
by
Florent Messa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change the way we handle default timeout for Django 1.6+
parent
1663885c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
8 deletions
+16
-8
cache.py
redis_cache/cache.py
+9
-8
compat.py
redis_cache/compat.py
+7
-0
No files found.
redis_cache/cache.py
View file @
c2ccc74a
...
...
@@ -2,7 +2,8 @@ from django.core.cache.backends.base import BaseCache, InvalidCacheBackendError
from
django.core.exceptions
import
ImproperlyConfigured
from
django.utils
import
importlib
from
django.utils.datastructures
import
SortedDict
from
.compat
import
smart_text
,
smart_bytes
,
bytes_type
,
python_2_unicode_compatible
from
.compat
import
(
smart_text
,
smart_bytes
,
bytes_type
,
python_2_unicode_compatible
,
DEFAULT_TIMEOUT
)
try
:
import
cPickle
as
pickle
...
...
@@ -45,8 +46,8 @@ class CacheConnectionPool(object):
self
.
_connection_pools
=
{}
def
get_connection_pool
(
self
,
host
=
'127.0.0.1'
,
port
=
6379
,
db
=
1
,
password
=
None
,
parser_class
=
None
,
unix_socket_path
=
None
):
password
=
None
,
parser_class
=
None
,
unix_socket_path
=
None
):
connection_identifier
=
(
host
,
port
,
db
,
parser_class
,
unix_socket_path
)
if
not
self
.
_connection_pools
.
get
(
connection_identifier
):
connection_class
=
(
...
...
@@ -162,7 +163,7 @@ class CacheClass(BaseCache):
key
=
CacheKey
(
key
)
return
key
def
add
(
self
,
key
,
value
,
timeout
=
None
,
version
=
None
):
def
add
(
self
,
key
,
value
,
timeout
=
DEFAULT_TIMEOUT
,
version
=
None
):
"""
Add a value to the cache, failing if the key already exists.
...
...
@@ -201,14 +202,14 @@ class CacheClass(BaseCache):
else
:
return
False
def
set
(
self
,
key
,
value
,
timeout
=
None
,
version
=
None
,
client
=
None
,
_add_only
=
False
):
def
set
(
self
,
key
,
value
,
timeout
=
DEFAULT_TIMEOUT
,
version
=
None
,
client
=
None
,
_add_only
=
False
):
"""
Persist a value to the cache, and set an optional expiration time.
"""
if
not
client
:
client
=
self
.
_client
key
=
self
.
make_key
(
key
,
version
=
version
)
if
timeout
is
None
:
if
timeout
is
DEFAULT_TIMEOUT
:
timeout
=
self
.
default_timeout
# If ``value`` is not an int, then pickle it
...
...
@@ -269,7 +270,7 @@ class CacheClass(BaseCache):
recovered_data
[
map_keys
[
key
]]
=
value
return
recovered_data
def
set_many
(
self
,
data
,
timeout
=
None
,
version
=
None
):
def
set_many
(
self
,
data
,
timeout
=
DEFAULT_TIMEOUT
,
version
=
None
):
"""
Set a bunch of values in the cache at once from a dict of key/value
pairs. This is much more efficient than calling set() multiple times.
...
...
@@ -324,7 +325,7 @@ class RedisCache(CacheClass):
ttl
=
self
.
_client
.
ttl
(
old_key
)
if
value
is
None
:
raise
ValueError
(
"Key '
%
s' not found"
%
key
)
new_key
=
self
.
make_key
(
key
,
version
=
version
+
delta
)
new_key
=
self
.
make_key
(
key
,
version
=
version
+
delta
)
# TODO: See if we can check the version of Redis, since 2.2 will be able
# to rename volitile keys.
self
.
set
(
new_key
,
value
,
timeout
=
ttl
)
...
...
redis_cache/compat.py
View file @
c2ccc74a
import
sys
import
django
PY3
=
(
sys
.
version_info
>=
(
3
,))
...
...
@@ -17,6 +18,12 @@ if PY3:
else
:
bytes_type
=
str
if
django
.
VERSION
[:
2
]
>=
(
1
,
6
):
from
django.core.cache.backends.base
import
DEFAULT_TIMEOUT
as
DJANGO_DEFAULT_TIMEOUT
DEFAULT_TIMEOUT
=
DJANGO_DEFAULT_TIMEOUT
else
:
DEFAULT_TIMEOUT
=
None
def
python_2_unicode_compatible
(
klass
):
"""
...
...
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