Skip to main content

A self updating dictionary like structure

Project description

Time Dictionary

Unittests

Now objects age too! - Automatically manage your objects based on age

How to install

> pip install timedict

Overview

This module implements self-updating structure that is able to handle updating and removing object based on age. Objects added to this structure are assigned timestamp at insertion, then when age of object is exceeded optional action function is called and object is removed from the structure.

NOTE

When using this structure you must explicitly delete it due to thread locking either by calling destroy() method or deleting it as del d or the interpreter will hang at exit

Example Usage

from time_dict import TimeDict
cache = TimeDict(action_time=2, poll_time=0.5)
key = '1'
cache[key] = 1
key in cache
del cache

Main parameters are:

action_time - which specifies age in second at which objects should be deleted - 
            time when actions should be performed and object will be deleted from structure

poll_time - frequency in seconds of polling the objects for age timeout,
            experimentally should be around 1/4 of the action_time or less. 
            Please not that too frequent polling
            may negatively affect you application performance

action  -   function that is called on object age timeout. 
            Signature is 'fn(key:Any, value:Any) -> None'

no_delete - do not delete objects when actions was called

Class PARTIALLY implements dictionary interface, implementations allows for:

d = TimeDict(action_time=2, poll_time=0.5)
insertion:
    d[key] = value
updating:
    NOTE: updating only changes the value, age remains unchanged
    d[key] = value
deletion:
      del d[key]
testing for membership:
    key in d
checking length:
    len(d)

All of the above method have optimistic time complexity of O(1)

Rest of the dictionary interface is not implemented by design.

Methods are:

clear() → None

Safely clear all data in the structure :raises Exception

destroy() → None

Destroys the structure, must be called to properly deinitialize it

flush() → None

Flush all the objects by calling the action function, does not remove objects Does not respect object age, calls action method on all objects :raises Exception if updated thread died

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timedict-0.0.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

timedict-0.0.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file timedict-0.0.3.tar.gz.

File metadata

  • Download URL: timedict-0.0.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0

File hashes

Hashes for timedict-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2333961144f02b8ed4e45efc31b6225ac2fca402bae965ecf9e439492f3e3750
MD5 0ad185559f5ceada11fff6c276ff8b42
BLAKE2b-256 39226a9fabebc880d60aad9b4e5c2c12c16a675003cf8a37b28638e622a26ba0

See more details on using hashes here.

File details

Details for the file timedict-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: timedict-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0

File hashes

Hashes for timedict-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9efea83ab9a49df7c10ddd27f0cfadbe57a48a8d369b4bb909e9df7dc89d93e4
MD5 6dcc7273963353c2de3de8073c15ac26
BLAKE2b-256 1ce2ede4571908faeb053356edf337352eb009f97c05e69ab776103fd0ce91cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page