-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feature Request: TTL only Cache #12
Comments
@elbaro Could you please elaborate on the use cases for unlimited and empty? Theine uses several queues and LRUs to improve hit ratio, all of which are size-aware. If size is set to unlimited or 0, the eviction policy will not work. |
@Memoize(Cache("unlimited"), timedelta(seconds=10)) # config rarely changes, so fetch once every 10 second
def get(config_name):
return mysql_client.query(f"SELECT * .. WHERE name = {config_name}")[0].value While This is similar to
The benefit of having a deciated class for this is to avoid the overhead of None, which is small. This feature request is optional. reverse_index = {}
@Memoize(Cache("unlimited"), timedelta(seconds=10 * 60))
def update(key):
value1, value2 = query(key)
reverse_index[value1] = key
reverse_index[value2] = key
# we want to keep reverse_index update-to-date
# but not interested in the returned value of update(key).
return None # Cache stores None which is a waste |
@elbaro The first case is very simple. I think a dictionary with a TTL field is sufficient. In your second example, what's the purpose of cache? If you want to cache |
reverse_index is a global dict that is shared by multiple keys. It can lookup with
This will create a reverse index for each key. Given Another example without data mapping: @Memoize(Cache("?"), timedelta(seconds=10))
def log_error(err) -> None: # log each type of error at most once every 10 seconds
write_to_file(err) |
@elbaro I see. So how about adding a @Memoize(Cache("simple", 1), timedelta(seconds=100))
def foo(a:int) -> int:
return a
@foo.key
def _(a:int) -> str:
return "foo" |
|
The text was updated successfully, but these errors were encountered: