'Remove specific part of a value in flask cache after certain time

I am dealing with a use case where in i want to delete certain part of a key's value

I am using Cache from flask_caching reference - https://flask-caching.readthedocs.io/en/latest/#

Example

Setting a value

key = 'xyz'
value = {'x':'1', 'y':'2'}
cache.set(key, value, timeout=300)

Updating a value

value = cache.get(key)
value['z'] = 3
cache.set(key, value, timeout=5)

now after 5 seconds when i hit

value = cache.get(key)

I get None but i want the initial value that i added i.e. {'x':'1', 'y':'2'} to stay till 300 seconds and only the latest update to that value should be deleted after 5 seconds



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source