You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, it not easy to discover what the archive/cache keys are. For example, an archive stored on disk will most likely have encoded keys, so it's not transparent from disk what the key is -- the keys are often loaded and displayed in their encrypted form, so figuring out what the keys actually are (in terms of the arguments of the cached function) can be overly difficult.
The text was updated successfully, but these errors were encountered:
klepto provides the interface to do the following...
>>> from klepto import lru_cache as memoize
>>> from klepto.keymaps import hashmap
>>> hasher = hashmap(algorithm='md5')
>>> @memoize(keymap=hasher, ignore=('self','**'))
... def _add(x, *args, **kwds):
... debug = kwds.get('debug', False)
... if debug:
... print ('debug:', x, args, kwds)
... return sum((x,)+args)
...
>>> _add(2,0)
2
>>> _add(0,2)
2
>>> _add(1,2)
3
>>> _add(4)
4
>>> _add.key(2,0)
'cfd9809c56982c2baf98916f82b19a4e'
>>>
>>> _add.__cache__()
null_archive({'d13d91f7c517f665d5c584a2edba0ff8': 2, 'aa6b0b0fae8513f6313f0543e05ec6a1': 3, '9803fa8027cfc9928f8648c89ad15f38': 4, 'cfd9809c56982c2baf98916f82b19a4e': 2}, cached=True)
>>> _add.key(2,0)
'cfd9809c56982c2baf98916f82b19a4e'
>>>
>>> _add.__map__()
hashmap(algorithm='md5')
>>> _add.__map__().decode(_add.key(2,0))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mmckerns/lib/python2.7/site-packages/klepto-0.1.2.dev-py2.7.egg/klepto/keymaps.py", line 176, in decode
raise NotImplementedError("Key decoding is not implemented")
NotImplementedError: Key decoding is not implemented
However, (1) decode is not implemented, and (2) for many keymaps (such as md5), it is not possible to recover the encrypted key… unless the encrypted keys are stored in a registry somewhere. For archives stored on disk or database, one could store such a registry fairly easily.
For all reversible encodings (such as pickle), there would seem to be more hope for decoding, however… the keymap.encode and keymap.encrypt functions involve irreversible operations such as sorting the keywords. Hence, apparently the only way to discover the key from a encoded/encrypted cache key would be to store the pairing as the key is encrypted.
Currently, it not easy to discover what the archive/cache keys are. For example, an archive stored on disk will most likely have encoded keys, so it's not transparent from disk what the key is -- the keys are often loaded and displayed in their encrypted form, so figuring out what the keys actually are (in terms of the arguments of the cached function) can be overly difficult.
The text was updated successfully, but these errors were encountered: