I am trying to make some of the in-memory dictionaries in my code persistent using bsddb 4.3. Here is an example dictionary in my code for which I would like to create a persistent version:
I plan to convert each key in the dictionary into a string using cPickle before I can store the key in the persistent hash.
I am looking for a way to store the values in the dictionary. Since each value is a dictionary, I am not sure how exactly to pickle it. Each value in the hash table is likely to get updated quite often; hence I need an efficient way to pickle and unpickle the values. Any ideas? Please help.
Thanks,
D.
Code:
# Example dictionary
patterns = {pat1: {t1:None},
pat2: {t1:None, t2:None},
pat3: {t2:None}}
# Each key is an instance of the class T
# Each value is a dictionary, where keys are instances of the class T, and values are None. I could have used set instead of dictionary here
# Sample instance data
t1 = T('John','age','35')
t2 = T('John','created','www.blogger.com')
pat1 = T('John','age',None)
pat2 = T('John',None,None)
pat3 = T('John','created',None)
class T(tuple):
def __new__(cls,*args):
a,b,c= tuple(args)
return tuple.__new__(cls,(a,b,c))
I am looking for a way to store the values in the dictionary. Since each value is a dictionary, I am not sure how exactly to pickle it. Each value in the hash table is likely to get updated quite often; hence I need an efficient way to pickle and unpickle the values. Any ideas? Please help.
Thanks,
D.
Comment