forked from django-tastypie/django-tastypie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.py
39 lines (31 loc) · 926 Bytes
/
cache.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from django.core.cache import cache
class NoCache(object):
"""
A simplified, swappable base class for caching.
Does nothing save for simulating the cache API.
"""
def get(self, key):
"""
Always returns ``None``.
"""
return None
def set(self, key, value, timeout=60):
"""
No-op for setting values in the cache.
"""
pass
class SimpleCache(NoCache):
"""
Uses Django's current ``CACHE_BACKEND`` to store cached data.
"""
def get(self, key):
"""
Gets a key from the cache. Returns ``None`` if the key is not found.
"""
return cache.get(key)
def set(self, key, value, timeout=60):
"""
Sets a key-value in the cache.
Optionally accepts a ``timeout`` in seconds. Defaults to ``60`` seconds.
"""
cache.set(key, value, timeout)