A class for caching in a session.
Project description
Session Cache
Description
Session Cache is a Python package that provides a simple and efficient way to store and manage cached data for a session. It allows users to cache data during a session and automatically clean up expired data at regular intervals.
Utility
Session Cache is useful for scenarios where temporary data storage is required within a session, such as web applications, API caching, or any situation where quick access to cached data is needed.
Install
You can install the session-cache package via pip:
pip install ran-cache
Examples of Basic Uses
from scache import SessionCache as Cache
from time import sleep
# Create a session cache with default settings (ttl=1 hour, cleanup_interval=2.5 hours)
# If 'cleanup_config' is an integer > 0, automatic cleanup is started automatically
cache = Cache() # default_ttl=3600, cleanup_config=9000
# Add data to the cache with default_ttl
cache.update('default_ttl', cache.default_ttl)
# Add data to the cache with custom ttl
cache.update('custom_ttl', 'custom', ttl=4) # 4 seconds
# Add data to the cache without ttl
cache.update('persistent_data', 'persistent', ttl=None)
# Retrieve cached values
default_ttl = cache.get("default_ttl")
custom_ttl = cache.get("custom_ttl")
print(default_ttl) # Returns 3600
print(custom_ttl) # Returns "custom"
sleep(4)
# Check cached values after expiration
default_ttl = cache.get("default_ttl")
custom_ttl = cache.get("custom_ttl")
print(default_ttl) # Returns 3600
print(custom_ttl) # Returns None
# Change default_ttl
cache.default_ttl = 2
# Check if automatic cleanup is enabled
print(cache.cleaning_enabled) # Returns True
# Stop automatic cleanup
cache.stop_cleanup()
print(cache.cleaning_enabled) # Returns False
# Start automatic cleanup
cache.start_cleanup()
print(cache.cleaning_enabled) # Returns True
# Automatic cleanup interval
print(cache.cleanup_config) # Returns 9000
# Change automatic cleanup interval to 1 minute
cache.cleanup_config = 60
print(cache.cleanup_config) # Returns 60
# Update a cached value and apply Default TTL (2 seconds)
cache.update("default_ttl", "new_value")
print(cache.get("default_ttl")) # Returns "new_value"
sleep(2)
print(cache.get("default_ttl")) # Returns None
Contact
For any inquiries or feedback regarding this project, please contact us on Discord
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ran-cache-0.1.0.tar.gz.
File metadata
- Download URL: ran-cache-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0aa90f4f56cda576e5b44fd00f8b114eeb96bb82634506e33340128f04db32d
|
|
| MD5 |
79fa80d5c4e1ffd6bbb8a01e31e67f20
|
|
| BLAKE2b-256 |
ae3115302cf8c0cf8d7a8dcb1347e25a056a3b3ea638943f125aa7dd9b79f35e
|
File details
Details for the file ran_cache-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ran_cache-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a80f5c39d2055ef27ff89f36dfb0316bfa340e5304c21ee2d7c55cab3f160148
|
|
| MD5 |
31c3f07afad09f28b150a7e007e88f9b
|
|
| BLAKE2b-256 |
c14ad7dac61ed5de2841576e98c9150056a21feb04fff4b6bd9d040323395e1a
|