# simplememcache
[![PyPI version](https://badge.fury.io/py/simplememcache.svg)](https://badge.fury.io/py/simplememcache)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/aj-jaiswal007/SimpleMemCache/blob/main/LICENSE)
`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:
```bash
pip install simplememcache
```
## Importing the package
```python
from simplememcache.lru import LRUCache
```
## Creating a cache instance
```python
# Create an LRU cache with a maximum size of 100 items
cache = LRUCache(max_size=100)
```
## Inserting items into the cache
```python
cache.insert("key1", "value1")
cache.insert("key2", 42)
```
## Getting items from the cache
```python
value = cache.get("key1")
print(value) # Output: "value1"
```
## Getting items with default value
```python
value = cache.get_or_default("nonexistent_key", default="default_value")
print(value) # Output: "default_value"
```
## Upserting items into the cache
```python
# 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
```python
deleted_value = cache.delete("key2")
print(deleted_value) # Output: 42
```
## Deleting items with default value
```python
deleted_value = cache.delete_or_default("nonexistent_key", default="default_value")
print(deleted_value) # Output: "default_value"
```
## Checking the size of the cache
```python
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](https://github.com/aj-jaiswal007/SimpleMemCache).
# License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/aj-jaiswal007/SimpleMemCache/blob/master/LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": "https://github.com/aj-jaiswal007/SimpleMemCache",
"name": "simplememcache",
"maintainer": "aj-jaiswal007",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "MEMCACHE,CACHE,PYTHON CACHE,SIMPLE CACHE,LRU CACHE",
"author": "Amar Jaiswal",
"author_email": "aj.jaiswal007@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/87/2c/fc8f6d89519afb94f90c6692fe40b2e6e088ba4d3ec4efbaa9a606357465/simplememcache-0.0.0a0.tar.gz",
"platform": null,
"description": "# simplememcache\n\n[![PyPI version](https://badge.fury.io/py/simplememcache.svg)](https://badge.fury.io/py/simplememcache)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/aj-jaiswal007/SimpleMemCache/blob/main/LICENSE)\n\n`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.\n\n## Installation\n\nYou can install `simplememcache` using pip:\n\n```bash\npip install simplememcache\n```\n\n\n## Importing the package\n```python\nfrom simplememcache.lru import LRUCache\n```\n\n## Creating a cache instance\n```python\n# Create an LRU cache with a maximum size of 100 items\ncache = LRUCache(max_size=100)\n```\n\n## Inserting items into the cache\n```python\ncache.insert(\"key1\", \"value1\")\ncache.insert(\"key2\", 42)\n```\n\n## Getting items from the cache\n```python\nvalue = cache.get(\"key1\")\nprint(value) # Output: \"value1\"\n```\n\n## Getting items with default value\n```python\nvalue = cache.get_or_default(\"nonexistent_key\", default=\"default_value\")\nprint(value) # Output: \"default_value\"\n```\n\n## Upserting items into the cache\n```python\n# Upsert (update or insert) an item into the cache\nresult = cache.upsert(\"key1\", \"new_value\")\nprint(result) # Output: False (key1 already existed, value updated)\n```\n\n## Deleting items from the cache\n```python\ndeleted_value = cache.delete(\"key2\")\nprint(deleted_value) # Output: 42\n```\n\n## Deleting items with default value\n```python\ndeleted_value = cache.delete_or_default(\"nonexistent_key\", default=\"default_value\")\nprint(deleted_value) # Output: \"default_value\"\n```\n\n## Checking the size of the cache\n```python\ncache_size = cache.size\nprint(cache_size) # Output: 1\n```\n\n# Contributing\nFeel free to contribute by opening issues or submitting pull requests on the [GitHub repository](https://github.com/aj-jaiswal007/SimpleMemCache).\n\n# License\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/aj-jaiswal007/SimpleMemCache/blob/master/LICENSE) file for details.\n\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Simple mem cache client for python",
"version": "0.0.0a0",
"project_urls": {
"Homepage": "https://github.com/aj-jaiswal007/SimpleMemCache"
},
"split_keywords": [
"memcache",
"cache",
"python cache",
"simple cache",
"lru cache"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ffcab56f4f5a5a1ccead8c2028678d51144c95dd8fa430bd42f9f5cf2543e8e0",
"md5": "31d0d3247d61411dcf804a6aead5a546",
"sha256": "b90b92737a1d6123fc3617c2e28c687efb555dc00efa7e1216cb7b1675cac378"
},
"downloads": -1,
"filename": "simplememcache-0.0.0a0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "31d0d3247d61411dcf804a6aead5a546",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 5782,
"upload_time": "2024-01-25T13:37:35",
"upload_time_iso_8601": "2024-01-25T13:37:35.447071Z",
"url": "https://files.pythonhosted.org/packages/ff/ca/b56f4f5a5a1ccead8c2028678d51144c95dd8fa430bd42f9f5cf2543e8e0/simplememcache-0.0.0a0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "872cfc8f6d89519afb94f90c6692fe40b2e6e088ba4d3ec4efbaa9a606357465",
"md5": "f76b540faab9a721ce8aef54eb0270c2",
"sha256": "9c2403b4507edaa03800eaf67548abf7fd540ad2b3bc80558ee8527be361d82e"
},
"downloads": -1,
"filename": "simplememcache-0.0.0a0.tar.gz",
"has_sig": false,
"md5_digest": "f76b540faab9a721ce8aef54eb0270c2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5485,
"upload_time": "2024-01-25T13:37:37",
"upload_time_iso_8601": "2024-01-25T13:37:37.852504Z",
"url": "https://files.pythonhosted.org/packages/87/2c/fc8f6d89519afb94f90c6692fe40b2e6e088ba4d3ec4efbaa9a606357465/simplememcache-0.0.0a0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-25 13:37:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aj-jaiswal007",
"github_project": "SimpleMemCache",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "simplememcache"
}