Fcache: File-Based Cache

0.6.0 · active · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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.

from fcache.cache import FileCache

# Create a cache named 'myapp' in a default location
mycache = FileCache('myapp')

# Store data
mycache['greeting'] = 'Hello, Fcache!'
mycache['number'] = 123

# Retrieve data
print(f"Retrieved greeting: {mycache['greeting']}")
print(f"Retrieved number: {mycache['number']}")

# Check if a key exists
print(f"'greeting' in cache: {'greeting' in mycache}")

# Update data
mycache['greeting'] = 'Hola, Fcache!'
print(f"Updated greeting: {mycache['greeting']}")

# Close the cache to ensure data is flushed (important!)
mycache.close()

# Re-open and verify persistence
another_cache_instance = FileCache('myapp')
print(f"Re-opened greeting: {another_cache_instance['greeting']}")
another_cache_instance.close()

view raw JSON →