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
Built Distribution
File details
Details for the file simplememcache-0.0.0a0.tar.gz
.
File metadata
- Download URL: simplememcache-0.0.0a0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c2403b4507edaa03800eaf67548abf7fd540ad2b3bc80558ee8527be361d82e |
|
MD5 | f76b540faab9a721ce8aef54eb0270c2 |
|
BLAKE2b-256 | 872cfc8f6d89519afb94f90c6692fe40b2e6e088ba4d3ec4efbaa9a606357465 |
File details
Details for the file simplememcache-0.0.0a0-py2.py3-none-any.whl
.
File metadata
- Download URL: simplememcache-0.0.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b90b92737a1d6123fc3617c2e28c687efb555dc00efa7e1216cb7b1675cac378 |
|
MD5 | 31d0d3247d61411dcf804a6aead5a546 |
|
BLAKE2b-256 | ffcab56f4f5a5a1ccead8c2028678d51144c95dd8fa430bd42f9f5cf2543e8e0 |