Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a new parameter in cache wrapper #23

Open
luckystar1992 opened this issue Jun 14, 2022 · 0 comments
Open

add a new parameter in cache wrapper #23

luckystar1992 opened this issue Jun 14, 2022 · 0 comments

Comments

@luckystar1992
Copy link

All things works fine when I used cache wrapper in the examples. But I met a big problem if I want to cache a inner function when design a lazy query tools. For example:

from memoization  import cached

class LazyQuery:
    def __init__:
        self.pipeline = list()
        self.cache = cached(max_size=10, ttl=10)

    def query1(**args):
        @cached
        def func():
              # do something()
            self.pipeline.append(func)
        return self

    def query2(**args):
        @cached
        def func():
              # do something()
            self.pipeline.append(func)
        return self

    # other query function with inner funciton cache wrapper

    def run():
        _input, _output_ = None, None
        for step in self.pipeline:
            _output = step(_input)
           _input = _output
        return _output


if __name__ == "__main__":
    lazy_query = LazyQuery()
    for i in range(5):
        lazy_query.query1().query2().run()
        lazy_query.pipeline.clear()

In fact, each inner cache wrapper funciton in every query has its own cache structures, like id(cache) in caching/lru_cache.py get_caching_wrapper(). Therefore, If the cached wrapper can add an extra position paramerter cache after custom_key_maker would be better.

def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe, order_independent, custom_key_maker, cache):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant