Documentation ¶
Overview ¶
Package ramcache implements the driver.Cache interface using an in-memory map.
It's useful for testing, development, and caching small data sets. It's not recommended for production due to lack of data persistence across restarts.
URL Format ¶
The URL should have the following format:
ramcache://[?query]
The optional query part can be used to configure the in-memory cache options through query parameters. The keys of the query parameters should match the case-insensitive field names of the Options structure.
Value Types ¶
Values being set in the cache should be of type [][byte], [string], or implement one of the following interfaces:
Usage ¶
import ( "context" "log" "github.com/bartventer/gocache" _ "github.com/bartventer/gocache/ramcache" ) func main() { ctx := context.Background() urlStr := "ramcache://?cleanupinterval=1m" c, err := cache.OpenCache(ctx, urlStr) if err != nil { log.Fatalf("Failed to initialize cache: %v", err) } // ... use c with the cache.Cache interface }
You can create a RAM cache with New:
import ( "context" "github.com/bartventer/gocache/ramcache" ) func main() { ctx := context.Background() c := ramcache.New[string](ctx, &ramcache.Options{ CleanupInterval: 1 * time.Minute, }) // ... use c with the cache.Cache interface }
Limitations ¶
Please note that due to the limitations of the RAM Cache, pattern matching operations are not supported. This includes the cache.Cache Count and DelKeys methods, which will return a cache.ErrPatternMatchingNotSupported error if called.
Index ¶
Constants ¶
const Scheme = "ramcache"
Scheme is the cache scheme for the in-memory cache.
Variables ¶
This section is empty.