file_memoized(serializer,
deserializer,
pathfunc)
| source code
|
The string result of the given function is saved to the given
path.
Example:
@file_memoized(lambda x,f: f.write(x),
lambda f: f.read(),
lambda: "/tmp/cache")
def foo(): return "hello"
@file_memoized(pickle.dump,
pickle.load,
lambda x,y: "/tmp/cache-%d-%d" % (x,y))
def foo(x,y): return "hello %d %d" % (x,y)
- Parameters:
serializer (function) - The function to serialize the return value into a string. This
should take the return value object and the file object.
deserializer (function) - The function te deserialize the cache file contents into the
return value. This should take the file object and return a
string.
pathfunc (str) - Returns the path where the files should be saved. This should be
able to take the same arguments as the original function.
|