Fcache is a Python library that provides a dictionary-like, file-based cache module. It is designed to be simple to use, includes an optional write buffer, and is compatible with Python's `shelve` module. The current version is 0.6.0, and releases occur on an as-needed basis, with the last major update in late 2024.
pip install fcacheVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a `FileCache`, store and retrieve data, check for key existence, update values, and properly close the cache to ensure data persistence. Re-opening verifies that the data is saved to disk.
Always call `.close()` on your `FileCache` instance when it's no longer needed, or use it within a `with` statement if context manager support is available (check documentation for future versions).
Periodically clear stale or unnecessary entries using `del mycache[key]` or `mycache.clear()` for the entire cache. Monitor disk usage of your cache directory.
Use `FileCache.delete()` with extreme caution and ensure it's the intended action to completely destroy the cache. Consider backups if the cached data is critical.
For highly concurrent or multi-process environments, implement external locking or ensure that only one process/thread modifies a specific cache instance at a time. Consult `shelve` documentation for its concurrency guarantees.
Check if the key exists before accessing it, or use the `.get()` method with a default value. For example: `value = mycache.get('some_key', default_value)` or `if 'some_key' in mycache: value = mycache['some_key']`Ensure the directory specified for the `FileCache` instance has appropriate write permissions for the user running the Python script, or specify a cache directory where write permissions are granted. For example, `mycache = FileCache('myapp', flag='cs', app_cache_dir='/tmp/my_cache_dir')`First, install the library using pip: `pip install fcache`. Then, ensure the correct import statement is used: `from fcache.cache import FileCache`
No dependency data recorded yet.