Skip to main content

Python decorators for store in-data memory using LRU cache

Project description

LRU Cache

Package for tracking store in-data memory using replacement cache algorithm / LRU cache. The Priority of storing or removing the data based on Min-Max heap algorithm or basic priority queue instead using OrderedDict module that provided by Python.

Purpose

The purpose of using this package itself is at least to be able to dynamically tracking. inserting, and removing least frequently used in-data memory or in an element. Another purposes, with the use of python decorator or the method looks like, it's also possible to figure it out whether the data in the cache is full or not (it's called LRU eviction), since LRU cache is using O(1) complexity, it's also possible to efficiently accessing the store in-data memory based on most frequently used method.

Usage

The package is still being under developed and haven't packaged and published into PyPi index. However, there is a little explanation regarding the use of this LRU cache. The basic usage is pretty common by using a List and accessing that List like example :

from lru import LRUCache

# set the max of cache capacity
foo = LRUCache(3)

# set the items
foo.set(1, "value")
foo.set(2, "cooke")
foo.set(3, "water")
foo.set(4, "gets")
foo.set(5, "sets")

# get the items
foo.get(3)
foo.get(4)
foo.get(5)

print(foo.get_dict())
print(foo.get_lru_element())

The get_dict() method returns a dictionary of an object with a maximum capacity of 3 (which was initialized at first), whereas the objects that taken from the dictionary based on objects that are recently used (this is indicated by the get() method), while the get_lru_element() method is used for retrieve an object based on the duration when accessing onto the dictionary.

For further example, hopefully this package can be backported with Python web frameworks such as Django or Flask which can be implemented and supported in the JSON field area, since the return of this LRUCache value is in the form of dictionary which is very common in JSON type.

Contributions

Since this package is still being under developed, any contributions are much welcomed and you can read on contribution page.

License

This package is licensed under the MIT License.

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

lruheap-0.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

lruheap-0.0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file lruheap-0.0.1.tar.gz.

File metadata

  • Download URL: lruheap-0.0.1.tar.gz
  • Upload date:
  • Size: 4.7 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.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

File hashes

Hashes for lruheap-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bee86fdfa095957d1adf744c467e395c06efa3090b90982ced81bb401fcdbcb2
MD5 933a96ec9fcffface7b7bfcef6cbb065
BLAKE2b-256 b5399c978e9bb8f7f4c3478923a019816bc28c5cb54438ddd26b8b5f5119b235

See more details on using hashes here.

File details

Details for the file lruheap-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: lruheap-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 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.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

File hashes

Hashes for lruheap-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0d4bc4fb7159441ae154a9292f6ee8246f42975122780c4da0578219e055a15a
MD5 0760f0faea94464745a47f69f39d4999
BLAKE2b-256 ebb7434f770fe3d0c8c0bcfc11848fd57c8510403b385cbd07ca4015921125c9

See more details on using hashes here.

Supported by

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