~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to swift/common/memcached.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-01-28 09:40:30 UTC
  • mfrom: (1.2.16)
  • Revision ID: package-import@ubuntu.com-20130128094030-aetz57x2qz9ye2d4
Tags: 1.7.6-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    return md5(key).hexdigest()
54
54
 
55
55
 
 
56
def sanitize_timeout(timeout):
 
57
    """
 
58
    Sanitize a timeout value to use an absolute expiration time if the delta
 
59
    is greater than 30 days (in seconds). Note that the memcached server
 
60
    translates negative values to mean a delta of 30 days in seconds (and 1
 
61
    additional second), client beware.
 
62
    """
 
63
    if timeout > (30 * 24 * 60 * 60):
 
64
        timeout += time.time()
 
65
    return timeout
 
66
 
 
67
 
56
68
class MemcacheConnectionError(Exception):
57
69
    pass
58
70
 
145
157
        :param timeout: ttl in memcache
146
158
        """
147
159
        key = md5hash(key)
148
 
        if timeout > 0:
149
 
            timeout += time.time()
 
160
        timeout = sanitize_timeout(timeout)
150
161
        flags = 0
151
162
        if serialize and self._allow_pickle:
152
163
            value = pickle.dumps(value, PICKLE_PROTOCOL)
217
228
        if delta < 0:
218
229
            command = 'decr'
219
230
        delta = str(abs(int(delta)))
 
231
        timeout = sanitize_timeout(timeout)
220
232
        for (server, fp, sock) in self._get_conns(key):
221
233
            try:
222
234
                sock.sendall('%s %s %s\r\n' % (command, key, delta))
284
296
        :param timeout: ttl for memcache
285
297
        """
286
298
        server_key = md5hash(server_key)
287
 
        if timeout > 0:
288
 
            timeout += time.time()
 
299
        timeout = sanitize_timeout(timeout)
289
300
        msg = ''
290
301
        for key, value in mapping.iteritems():
291
302
            key = md5hash(key)