Login

JSON instead of pickle for memcached

Author:
diverman
Posted:
January 10, 2012
Language:
Python
Version:
1.3
Score:
0 (after 0 ratings)

Standard memcache client uses pickle as a serialization format. It can be handy to use json, especially when another component (e.g. backend) doesn't know pickle, but json yes.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import memcache
import simplejson
 
class SimplejsonWrapper(object):
    def __init__(self, file, protocol=None):
        self.file = file
 
    def dump(self, value)
        simplejson.dump(value, self.file)
 
    def load(self):
        return simplejson.load(self.file)


cache = memcache.Client(['127.0.0.1:11211'], pickler=SimplejsonWrapper, unpickler=SimplejsonWrapper)

More like this

  1. codigo alto nivel by MrRocklion 1 month ago
  2. Load template from specific app by Krzysiek555 1 month, 3 weeks ago
  3. PostgreSQL JSON subqueries by dolamroth 1 month, 3 weeks ago
  4. "Magic Link" Management Command by webology 7 months ago
  5. Closest ORM models to a latitude/longitude point by simonw 7 months ago

Comments

Please login first before commenting.