<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -28,12 +28,19 @@ class memorise(object):
             to the same value as the cached return value. Handy for keeping
             models in line if attributes are accessed directly in other
             places, or for pickling instances.
+          `ttl` : integer
+            Tells memcached the time which this value should expire.
+            We default to 0 == cache forever. None is turn off caching.
+          `update` : boolean
+            Refresh ttl value in cache.
         &quot;&quot;&quot;
 
-        def __init__(self, mc=None, mc_servers=None, parent_keys=[], set=None):
+        def __init__(self, mc=None, mc_servers=None, parent_keys=[], set=None, ttl=0, update=False):
                 # Instance some default values, and customisations
                 self.parent_keys = parent_keys
                 self.set = set
+                self.ttl = ttl
+                self.update = update
                 if not mc:
                         if not mc_servers:
                                 mc_servers = ['localhost:11211']
@@ -93,16 +100,21 @@ class memorise(object):
                         if self.mc:
                                 # Try and get the value from memcache
                                 output = self.mc.get(key)
+                                exist = True
                                 if not output:
+                                        exist = False
                                         # Otherwise get the value from
                                         # the function/method
                                         output = fn(*args, **kwargs)
+                                if self.update or not exist:
                                         if output is None:
                                                 set_value = memcache_none()
                                         else:
                                                 set_value = output
                                         # And push it into memcache
-                                        self.mc.set(key, set_value)
+                                        if self.ttl != None:
+                                                print 'caching'
+                                                self.mc.set(key, set_value, time=self.ttl)
                                 if output.__class__ is memcache_none:
                                         # Because not-found keys return
                                         # a None value, we use the</diff>
      <filename>memorised/decorators.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>338857a07b5cd5c9eac05e995e1ca7cce73719e4</id>
    </parent>
  </parents>
  <author>
    <name>xmm</name>
    <email>xmm@xoxma.localnet</email>
  </author>
  <url>http://github.com/1stvamp/memorised/commit/87ae1586797eeb221453247409d99996781ce700</url>
  <id>87ae1586797eeb221453247409d99996781ce700</id>
  <committed-date>2009-10-27T20:40:51-07:00</committed-date>
  <authored-date>2009-10-27T20:40:51-07:00</authored-date>
  <message>Added ttl and update options</message>
  <tree>3d75c740a8e3b95be8666472f1f58a4ea5f5028b</tree>
  <committer>
    <name>xmm</name>
    <email>xmm@xoxma.localnet</email>
  </committer>
</commit>
