Commit 04448249 authored by Sean Bleier's avatar Sean Bleier

Update docs for new features.

parent 94eab537
...@@ -93,6 +93,13 @@ Standard Django Cache API ...@@ -93,6 +93,13 @@ Standard Django Cache API
:param version: Version of key :param version: Version of key
:type version: Integer or None :type version: Integer or None
.. function:: touch(self, key, timeout):
Updates the timeout on a key.
:param key: Location of the value
:rtype: bool
Cache Methods Provided by django-redis-cache Cache Methods Provided by django-redis-cache
...@@ -124,14 +131,22 @@ Cache Methods Provided by django-redis-cache ...@@ -124,14 +131,22 @@ Cache Methods Provided by django-redis-cache
:param version: Version of the keys :param version: Version of the keys
.. function:: get_or_set(self, key, func[, timeout=None]): .. function:: get_or_set(self, key, func[, timeout=None, lock_timeout=None, stale_cache_timeout=None]):
Get a value from the cache or call ``func`` to set it and return it.
Retrieves a key value from the cache and sets the value if it does not exist. This implementation is slightly more advanced that Django's. It provides thundering herd
protection, which prevents multiple threads/processes from calling the value-generating
function too much.
:param key: Location of the value :param key: Location of the value
:param func: Callable used to set the value if key does not exist. :param func: Callable used to set the value if key does not exist.
:param timeout: Number of seconds to hold value in cache. :param timeout: Time in seconds that value at key is considered fresh.
:type timeout: Number of seconds or None :type timeout: Number of seconds or None
:param lock_timeout: Time in seconds that the lock will stay active and prevent other threads from acquiring the lock.
:type lock_timeout: Number of seconds or None
:param stale_cache_timeout: Time in seconds that the stale cache will remain after the key has expired. If ``None`` is specified, the stale value will remain indefinitely.
:type stale_cache_timeout: Number of seconds or None
.. function:: reinsert_keys(self): .. function:: reinsert_keys(self):
...@@ -147,12 +162,9 @@ Cache Methods Provided by django-redis-cache ...@@ -147,12 +162,9 @@ Cache Methods Provided by django-redis-cache
:param key: Location of the value :param key: Location of the value
:rtype: bool :rtype: bool
.. function:: lock(self, key, timeout=None, sleep=0.1, blocking_timeout=None, thread_local=True)
.. function:: expire(self, key, timeout): See docs for `redis-py`_.
Set the expire time on a key
:param key: Location of the value
:rtype: bool
.. _redis-py: https://redis-py.readthedocs.io/en/latest/_modules/redis/client.html#Redis.lock
...@@ -4,7 +4,7 @@ Intro and Quick Start ...@@ -4,7 +4,7 @@ Intro and Quick Start
Intro Intro
===== =====
`django-redis-cache`_ is a cache backend for the `Django`_ webframework. It `django-redis-cache`_ is a cache backend for the `Django`_ web framework. It
uses the `redis`_ server, which is a in-memory key-value data structure server. uses the `redis`_ server, which is a in-memory key-value data structure server.
Similar to the great `Memcached`_ in performance, it has several features that Similar to the great `Memcached`_ in performance, it has several features that
makes it more appealing. makes it more appealing.
...@@ -24,7 +24,7 @@ makes it more appealing. ...@@ -24,7 +24,7 @@ makes it more appealing.
* Many more. * Many more.
Many of these features are irrelevant to caching, but can be used by other Many of these features are irrelevant to caching, but can be used by other
areas of a web stack and therefore offer a compelling case to simplify your areas of a web stack and therefore offers a compelling case to simplify your
infrastructure. infrastructure.
...@@ -35,7 +35,7 @@ Quick Start ...@@ -35,7 +35,7 @@ Quick Start
**Recommended:** **Recommended:**
* `redis`_ >= 2.4 * `redis`_ >= 2.8
* `redis-py`_ >= 2.10.3 * `redis-py`_ >= 2.10.3
......
...@@ -414,7 +414,7 @@ class BaseRedisCache(BaseCache): ...@@ -414,7 +414,7 @@ class BaseRedisCache(BaseCache):
timeout=DEFAULT_TIMEOUT, timeout=DEFAULT_TIMEOUT,
lock_timeout=None, lock_timeout=None,
stale_cache_timeout=None): stale_cache_timeout=None):
"""Get a value from the cache or call `func` to set it and return it. """Get a value from the cache or call ``func`` to set it and return it.
This implementation is slightly more advanced that Django's. It provides thundering herd This implementation is slightly more advanced that Django's. It provides thundering herd
protection, which prevents multiple threads/processes from calling the value-generating protection, which prevents multiple threads/processes from calling the value-generating
...@@ -422,11 +422,11 @@ class BaseRedisCache(BaseCache): ...@@ -422,11 +422,11 @@ class BaseRedisCache(BaseCache):
There are three timeouts you can specify: There are three timeouts you can specify:
`timeout`: Time in seconds that value at `key` is considered fresh. ``timeout``: Time in seconds that value at ``key`` is considered fresh.
`lock_timeout`: Time in seconds that the lock will stay active and prevent other threads or ``lock_timeout``: Time in seconds that the lock will stay active and prevent other threads or
processes from acquiring the lock. processes from acquiring the lock.
`stale_cache_timeout`: Time in seconds that the stale cache will remain after the key has ``stale_cache_timeout``: Time in seconds that the stale cache will remain after the key has
expired. If `None` is specified, the stale value will remain indefinitely. expired. If ``None`` is specified, the stale value will remain indefinitely.
""" """
if not callable(func): if not callable(func):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment