Package: mgdl-simple-cache
Simple CacheSimple Cache is a lightweight cache manager designed to simplify caching operations using Deta Base. It offers a convenient way to store and retrieve cached data efficiently in Python applications.InstallationInstall Simple Cache via pip:pipinstallmgdl-simple-cachePurposeIn today's data-driven applications, caching plays a crucial role in enhancing performance by reducing the need to repeatedly fetch data from external sources. Simple Cache aims to streamline this process by providing a user-friendly interface for managing cached data, backed by Deta Base, a fast and scalable database service.UsageTo usesimple-cache, you need to initialize an instance of theSimpleCacheclass. You can optionally provide a Deta Base key during initialization. If not provided during initialization, you can call theinit()method later to set the Deta Base key. You can change the table name passing a string as second argument toconstructororinitmethod, the default issc_cache.fromsimple_cacheimportSimpleCache# Initialize SimpleCachecache=SimpleCache("YOUR_DETA_PROJECT_KEY")# Orcache_with_table_name=SimpleCache(deta_key="YOUR_DETA_PROJECT_KEY",table_name="a_new_table_name")Orfromsimple_cacheimportSimpleCache# Initialize SimpleCachecache=SimpleCache()cache.init("YOUR_DETA_PROJECT_KEY")# Orcache_with_table_name=SimpleCache()cache_with_table_name.init(deta_key="YOUR_DETA_PROJECT_KEY",table_name="a_new_table_name")Methodsget(key: str) -> CacheDataRetrieve cached data associated with the specified key.key: The key corresponding to the cached data.Returns aCacheDataobject containing the cached value and its validity status.set(key: str, value: Any) -> CacheDataStore data in the cache under the given key.key: The key to associate with the cached data.value: The data to be cached.Returns aCacheDataobject representing the stored value and its validity status.set_validate(key: str, valid: bool, silent: bool = True) -> NoneUpdate the validity status of cached data.key: The key associated with the cached data.valid: A boolean value indicating whether the cached data is valid.silent: If True, suppress errors during the update process.Does not return any value.DocumentationCacheDataA simple class representing cached data.Attributesvalue: The cached value.valid: A boolean indicating whether the cached value is valid.SimpleCacheA class for managing cached data using Deta Base.Attributescache_table: The name of the table where cached data is stored, defaultsc_cache.deta: An instance of the Deta class.cache_db: An instance of the Deta Base class.Methods__init__(deta_key: Optional[str] = None, table_name: Optional[str] = None): Initialize the SimpleCache instance.init(deta_key: str, table_name: Optional[str] = None): Initialize the SimpleCache instance with the Deta Base key.get(key: str) -> CacheData: Retrieve cached data.set(key: str, value: Any) -> CacheData: Store data in the cache.set_validate(key: str, valid: bool, silent: bool = True) -> None: Update the validity status of cached data.LicenseThis project is licensed under the terms of the MIT license. See theLICENSEfile for details.ContributionContributions are welcome! Feel free to open issues or submit pull requests to enhance this project. Your feedback and contributions help make Simple Cache even better.