From 83fb66a9b5605c0d3b3bdaabf4ca9c4e866edfea Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 9 Apr 2012 17:10:55 -0400 Subject: - dont need pickle here --- docs/build/usage.rst | 19 +++++++++---------- 1 file 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 -- cgit v1.2.1