Skip to main content

A simple in-memory caching module like Memcached

Project description

CacheCraft

CacheCraft is a custom in-memory caching system designed to improve application performance by storing and retrieving data with low-latency access. This Project is fully inspired by Memcached

How to Use?

pip install CacheCraft

Example 1 (General Set & Get)

>>> from cachecraft.cache import CacheCraft
>>> cache = CacheCraft()
>>> cache.set('key', 'value')
>>> cache.get('key')
'value'

Example 2 (With Size and Default Time to live logic)

>>> cache = CacheCraft(max_size =100, default_ttl =2)
>>> cache.set('key', 'value')
>>> cache.get('key')
'value'
>>> import time; time.sleep(2)
>>> cache.get('key')
>>> 

Example 3 (Least Recently Used LRU)

# Size is 3 so, if 4rth key will be added then
# oldest used will be removed
>>> from cachecraft.cache import CacheCraft
>>> cache = CacheCraft(max_size=3, default_ttl=30)
>>> cache.set('a', 1)
>>> cache.set('b', 2)
>>> cache.set('c', 3)
>>> cache.get('a')
1
>>> cache.get('c')
3
>>> cache.set('d', 4)  # Once 'd' will set 'b' will be removed 
>>> cache.get('b')     # due to LRU
>>> 
Screenshot 2024-10-03 at 9 02 31 AM

Validating through Testcase

git clone git@github.com:Aditya-1998k/CacheCraft.git
pip install pytest
pytest tests/
Screenshot 2024-10-03 at 9 16 48 AM

Project Structure

CacheCraft/
├── cachecraft/
│   ├── __init__.py   # Package init file
│   ├── cache.py      # Core caching logic
├── tests/
│   ├── test_cache.py # pytest
├── setup.py          # Setup configuration for PyPI 
├── README.md         # Project description
└── LICENSE           # License file

Features

1. Key-value store
2. Expiration : Optionally set TTl (time to live)
3. LRU Eviction Policy : Automatically evicts the least recently used entries
6. Customizable: Modify cache size, eviction policy etc.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

cachecraft-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

CacheCraft-0.1.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file cachecraft-0.1.2.tar.gz.

File metadata

  • Download URL: cachecraft-0.1.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for cachecraft-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7607455c63aa9f2d3598b5cc222c28415c20030246d81de41529598ec16548e7
MD5 9682a4695dbc2edb17f38b1fca285323
BLAKE2b-256 1136326403ea35c86f7abe5dd2844bbde9be0b1af8d1c0709b179dc653459513

See more details on using hashes here.

File details

Details for the file CacheCraft-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: CacheCraft-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for CacheCraft-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 75c7031dddb80ae6fc026af348c3e8968ea24710f1f98ed95628987bd2e709ce
MD5 aacd28e8d40e6901ddde287a96685122
BLAKE2b-256 8dcbc63a0e79a472967a94439cb0a88f01399a8716ba6b6f0d8808578f1ac696

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