Skip to content

add a new parameter in cache wrapper #23

Description

@luckystar1992

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):

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions