title: Updating time for key in couchbase
body: <p>I have the system which sends concurrent <strong>get</strong> queries to couchbase. Every time the system gets <strong>existing</strong> key, it should update(prolongate) its lifetime. The amount of time is not so important and measures by days: the main idea is that key should be removed after nobody gets it for some time (20 days for example).</p>
  
  <p>I guess that <code>touch</code> operation should be used, but should I <code>lock</code> keys, which would make things more difficult? Is it ok to use memcached package (it seems does not have <code>lock</code> API, but perhaps <code>gets</code> should do the trick)?</p>
  
  <pre class="lang-py prettyprint-override"><code>import pylibmc
  
  
  class Cache(Singleton):
  
      def init(self):
          self.mc = pylibmc.Client(
              # connection settings here
          )
  
      def get(self, key):
          """get key without locking it and update lifetime"""
          result = self.mc.get(key)
          if result:
              # prolongate key for another 20 days
              self.mc.touch(key, 60*60*24*20)
  
          return result
  
       def get_and_lock(self, key):
           """lock the key while getting it and update lifetime"""
           # should use couchbase package as memcached does not have lock API
           # or use 'gets' instead?
  </code></pre>