Discover Packages
github.com/fufuok/cache
examples
cache-persistence
command
Version:
v1.1.0
Opens a new window with list of versions in this module.
Published: Sep 15, 2025
License: Apache-2.0
Opens a new window with license information.
Imports: 6
Opens a new window with list of imports.
Imported by: 0 modules, 0 packages
The first number is the count of modules that contain a package that imports this one.
The module count is a better indicator of popularity than the package count.
A module with 100 importing packages is counted only once instead of 100 times,
reflecting the fact that the choice to use the package was likely made only once,
not 100 times.
A '?' means that the value hasn't been computed yet.
Opens a new window with list of known importers.
README
README
¶
Cache Persistence Example
This example demonstrates how to use ItemsWithExpiration() and LoadItemsWithExpiration() to persist cache data to JSON files and restore it later.
Features Demonstrated
Export Cache to JSON : Use ItemsWithExpiration() to get all cache items with their expiration times and serialize to JSON
Import from JSON : Load JSON data back into cache using LoadItemsWithExpiration()
Flexible Loading : Show different strategies for loading cached data:
Load with original expiration times
Load with default expiration for all items
Load with custom/extended expiration times
What This Example Shows
Populating cache with various expiration settings
Exporting cache contents to a JSON file preserving expiration information
Clearing cache (simulating application restart)
Restoring cache from JSON with different expiration strategies
Handling expired items during restoration
Key Methods Used
cache.ItemsWithExpiration() - Get all items with expiration info
cache.LoadItemsWithExpiration(items) - Load items with specific expiration times
cache.LoadItems(items, expiration) - Load items with uniform expiration
JSON serialization/deserialization for persistence
Usage
cd examples/cache-persistence
go run main.go
The example will create a temporary cache_backup.json file during execution and clean it up automatically.
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.