summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-04-09 17:10:55 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-04-09 17:10:55 -0400
commit83fb66a9b5605c0d3b3bdaabf4ca9c4e866edfea (patch)
treed9b54b4ba873c379776e5e095f8b872613a59790
parent23d5354beb0272add195613c8689112485f6b9e3 (diff)
downloaddogpile-core-83fb66a9b5605c0d3b3bdaabf4ca9c4e866edfea.tar.gz
- dont need pickle here
-rw-r--r--docs/build/usage.rst19
1 files changed, 9 insertions, 10 deletions
diff --git a/docs/build/usage.rst b/docs/build/usage.rst
index c629ede..6d4b9f9 100644
--- a/docs/build/usage.rst
+++ b/docs/build/usage.rst
@@ -233,7 +233,6 @@ of ``(value, created_at)``, where it's assumed both have been retrieved from
the cache backend::
import pylibmc
- import pickle
import time
from dogpile import Dogpile, NeedRegenerationException, NameRegistry
@@ -247,21 +246,21 @@ the cache backend::
def get_or_create(key, expiration_time, creation_function):
def get_value():
with mc_pool.reserve() as mc:
- value = mc.get(key)
- if value is None:
+ value_plus_time = mc.get(key)
+ if value_plus_time is None:
raise NeedRegenerationException()
- # deserialize a tuple
+ # return a tuple
# (value, createdtime)
- return pickle.loads(value)
+ return value_plus_time
def gen_cached():
value = creation_function()
with mc_pool.reserve() as mc:
- # serialize a tuple
+ # create a tuple
# (value, createdtime)
- value = (value, time.time())
- mc.put(mangled_key, pickle.dumps(value))
- return value
+ value_plus_time = (value, time.time())
+ mc.put(key, value_plus_time)
+ return value_plus_time
dogpile = dogpile_registry.get(key, expiration_time)
@@ -292,7 +291,7 @@ Stepping through the above code:
instead of storing and retrieving the value alone from the cache, the value is
stored along with its creation time; when we make a new value, we set this
to ``time.time()``. While the value and creation time pair are stored here
- as a pickled tuple, it doesn't actually matter how the two are persisted;
+ as a tuple, it doesn't actually matter how the two are persisted;
only that the tuple value is returned from both functions.
* We acquire a new or existing :class:`.Dogpile` object from the registry using
:meth:`.NameRegistry.get`. We pass the identifying key as well as the expiration