Skip to content

Option to add trigger on delete#50

Open
jzr-supove wants to merge 1 commit intomailgun:masterfrom
jzr-supove:master
Open

Option to add trigger on delete#50
jzr-supove wants to merge 1 commit intomailgun:masterfrom
jzr-supove:master

Conversation

@jzr-supove
Copy link
Copy Markdown

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