cutcutcodec.core.opti.cache.basic

The not sofisticated cache decorators.

Functions

basic_cache(func)

Cache for hashable args.

method_cache(meth)

Cache a class method.

Details

cutcutcodec.core.opti.cache.basic.basic_cache(func: callable) callable[source]

Cache for hashable args.

Examples

>>> from cutcutcodec.core.opti.cache.basic import basic_cache
>>> i = 0
>>> @basic_cache
... def f(x):
...     global i
...     i += x
...     return i
...
>>> f(1)
1
>>> f(1)
1
>>>
cutcutcodec.core.opti.cache.basic.method_cache(meth: callable) callable[source]

Cache a class method.

Examples

>>> from cutcutcodec.core.opti.cache.basic import method_cache
>>> i = 0
>>> class Foo:
...     @method_cache
...     def f(self, x):
...         global i
...         i += x
...         return i
...
>>> foo = Foo()
>>> foo.f(1)
1
>>> foo.f(1)
1
>>>