Python in-memory cache with time to live

后端 未结 8 1542
后悔当初
后悔当初 2020-12-04 23:24

I have multiple threads running the same process that need to be able to to notify each other that something should not be worked on for the next n seconds its not the end o

8条回答
  •  长情又很酷
    2020-12-05 00:02

    You can also go for dictttl, which has MutableMapping, OrderedDict and defaultDict(list)

    Initialize an ordinary dict with each key having a ttl of 30 seconds

    data = {'a': 1, 'b': 2}
    dict_ttl = DictTTL(30, data)
    

    OrderedDict

    data = {'a': 1, 'b': 2}
    dict_ttl = OrderedDictTTL(30, data)
    

    defaultDict(list)

    dict_ttl = DefaultDictTTL(30)
    data = {'a': [10, 20], 'b': [1, 2]}
    [dict_ttl.append_values(k, v) for k, v in data.items()]
    

提交回复
热议问题