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

Option to add trigger on delete #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jzr-supove
Copy link

Trigger on delete

Add option to pass custom function that is executed when element being deleted, so that we can process elements before they gone

Example usage:

def process(key, value):
    print(key, value)


cache = ExpiringDict(max_len=2, max_age_seconds=1, on_delete=process)

cache[0] = "A"
cache[1] = "B"
cache[2] = "C"
cache[3] = "D"

Outputs:

0 A
1 B

Hotfix

Fixed issue when key gets deleted even though its updated recently

Example:

cache = ExpiringDict(max_len=2, max_age_seconds=1)

cache['r'] = "Red"
cache['g'] = "Green"
cache['r'] = "LightRed"
cache['b'] = "Blue"

print(cache)

Output before:

ExpiringDict([('g', 'Green'), ('b', 'Blue')])

Output after fix:

ExpiringDict([('r', 'LightRed'), ('b', 'Blue')])

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

Successfully merging this pull request may close these issues.

1 participant