klepto

Python Saving and Editing with Klepto

拜拜、爱过 提交于 2020-01-11 03:48:13
问题 Okay so my question is pretty specific and I apologize in advance. I'm a new programmer and tried developing on my own from scratch. It was relatively successful only I have one last problem, that I can see. You can view my code here in its entirety. Project So the problem I'm having is related to the way I save the file. I first tried to pickle it since it's a dictionary but I kept getting an error because my dictionary is (name, class) pairs. I searched around on here and saw I could try

Decorators for selective caching / memoization

喜你入骨 提交于 2019-12-21 17:42:17
问题 I am looking for a way of building a decorator @memoize that I can use in functions as follows: @memoize my_function(a, b, c): # Do stuff # result may not always be the same for fixed (a,b,c) return result Then, if I do: result1 = my_function(a=1,b=2,c=3) # The function f runs (slow). We cache the result for later result2 = my_function(a=1, b=2, c=3) # The decorator reads the cache and returns the result (fast) Now say that I want to force a cache update : result3 = my_function(a=1, b=2, c=3,

How to use LRU caching on disk with klepto?

两盒软妹~` 提交于 2019-12-14 02:44:03
问题 I am trying to use klepto to do LRU caching. I would like to store the cache to disk, and am currently using klepto's dir_archive option for this. I have written the following code, largely based on the code in the klepto test scripts: def mymap(data): return hashlib.sha256(data).hexdigest() class MyLRUCache: @lru_cache(cache=dir_archive(cached=False), keymap=mymap, ignore='self', maxsize=5) def __call__(self, data) return data call = __call__ def store(self, data): self.call(data) # I would