GithubHelp home page GithubHelp logo

ttlstore's Introduction

Installation:

pip install ttlstore

Getting started:

import time

from ttlstore import TTLStore


d = TTLStore(ttl=1) # use d like a python dictionary
d['a'] = 'b'
time.sleep(2)
# 'a' is not present any more in the memory
print(d)

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

d = TTLStore(ttl=1, callback=call_me)
d['a'] = 'b'
time.sleep(2)
# 'a' is not present any more in the memory and call_me is called.
print(d)

To run example script:

➜  python example.py
INFO:root:-------- executing example 1 ----------
DEBUG:root:contents of dict: {}
INFO:root:-------- end of example 1 ---------
INFO:root:-------- executing example 2 ----------
DEBUG:root:executing call back for deleted k: 1, v: 3
DEBUG:root:executing call back for deleted k: 2, v: 4
DEBUG:root:contents of dict: {}
INFO:root:-------- end of example 2 ---------
INFO:root:-------- executing example 3 ------
DEBUG:root:done inserting 1000 elements in a tight loop, time taken: 0.0015082359313964844
DEBUG:root:length of dict: 0
DEBUG:root:done inserting 10000 elements sporadically, time taken: 3.6316630840301514
DEBUG:root:length of dict: 0
INFO:root:-------- end of example 3 ----

To run tests:

python -m unittest -v tests/ttlstore_test.py

Unittest results:

 ➜ python -m unittest -v tests/ttlstore_test.py
test_basics (tests.ttlstore_test.TTLStoreTestCases) ... ok
test_create (tests.ttlstore_test.TTLStoreTestCases) ... ok
test_get (tests.ttlstore_test.TTLStoreTestCases) ... ok
test_iter (tests.ttlstore_test.TTLStoreTestCases) ... ok
test_not_implemented (tests.ttlstore_test.TTLStoreTestCases) ... ok
test_pop (tests.ttlstore_test.TTLStoreTestCases) ... ok
test_reset_of_key_no_trim (tests.ttlstore_test.TTLStoreTestCases)
Re-setting an existing key should not cause a non-expired key to be dropped ... ok
test_set (tests.ttlstore_test.TTLStoreTestCases) ... ok
test_setdefault (tests.ttlstore_test.TTLStoreTestCases) ... ok

----------------------------------------------------------------------
Ran 9 tests in 0.089s

OK

ttlstore's People

Contributors

grk-it avatar

Stargazers

 avatar  avatar bryan avatar

Watchers

Aren Sandersen avatar Travis Theune avatar bryan avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.