Simple mem cache client for python
Project description
simplememcache
simplememcache
is a lightweight Python package providing a simple and efficient Least Recently Used (LRU) cache implementation. It allows you to cache and manage key-value pairs with a maximum size, automatically evicting the least recently used items when the cache reaches its limit.
Installation
You can install simplememcache
using pip:
pip install simplememcache
Importing the package
from simplememcache.lru import LRUCache
Creating a cache instance
# Create an LRU cache with a maximum size of 100 items
cache = LRUCache(max_size=100)
Inserting items into the cache
cache.insert("key1", "value1")
cache.insert("key2", 42)
Getting items from the cache
value = cache.get("key1")
print(value) # Output: "value1"
Getting items with default value
value = cache.get_or_default("nonexistent_key", default="default_value")
print(value) # Output: "default_value"
Upserting items into the cache
# Upsert (update or insert) an item into the cache
result = cache.upsert("key1", "new_value")
print(result) # Output: False (key1 already existed, value updated)
Deleting items from the cache
deleted_value = cache.delete("key2")
print(deleted_value) # Output: 42
Deleting items with default value
deleted_value = cache.delete_or_default("nonexistent_key", default="default_value")
print(deleted_value) # Output: "default_value"
Checking the size of the cache
cache_size = cache.size
print(cache_size) # Output: 1
Contributing
Feel free to contribute by opening issues or submitting pull requests on the GitHub repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simplememcache-0.0.0a0.tar.gz
(5.5 kB
view hashes)
Built Distribution
Close
Hashes for simplememcache-0.0.0a0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b90b92737a1d6123fc3617c2e28c687efb555dc00efa7e1216cb7b1675cac378 |
|
MD5 | 31d0d3247d61411dcf804a6aead5a546 |
|
BLAKE2b-256 | ffcab56f4f5a5a1ccead8c2028678d51144c95dd8fa430bd42f9f5cf2543e8e0 |