glimr/cache/driver
Cache Store Configuration
Provides store types for configuring cache stores in a type-safe way. Users define stores in their config_cache.gleam file which is loaded at runtime.
Types
Represents a named cache store configuration. Each store has a name that identifies it and configuration parameters specific to the store type.
Use FileStore for file-based caching.
Use RedisStore for Redis-based caching.
Use DatabaseStore for database-backed caching.
pub type CacheStore {
FileStore(name: String, path: String)
RedisStore(
name: String,
url: Result(String, String),
pool_size: Result(Int, String),
)
DatabaseStore(name: String, database: String, table: String)
}
Constructors
-
FileStore(name: String, path: String) -
RedisStore( name: String, url: Result(String, String), pool_size: Result(Int, String), ) -
DatabaseStore(name: String, database: String, table: String)
Values
pub fn find_by_name(
name: String,
stores: List(CacheStore),
) -> CacheStore
Searches through a list of stores to find one with the specified name. Panics if no store matches the given name in the configuration.
pub fn find_database_store(
database: String,
stores: List(CacheStore),
) -> Result(CacheStore, String)
Searches through a list of stores to find a DatabaseStore for the specified database connection name. Returns Ok with the store if exactly one is found, or an Error describing the problem (none found or multiple found).
pub fn store_name(store: CacheStore) -> String
Returns the name identifying this store configuration. The name is used to look up specific stores when multiple cache stores are configured in the app.
pub fn store_path(store: CacheStore) -> String
Returns the path for a FileStore, or panics if called on other store types. Use store_type to check the backend before calling this function.
pub fn store_table(store: CacheStore) -> String
Returns the table name for a DatabaseStore, or panics if called on other store types. Use store_type to check the backend before calling this function.
pub fn store_type(store: CacheStore) -> StoreType
Returns whether the store is File, Redis, or Database. Extracts the underlying backend type from a CacheStore without exposing the specific configuration parameters.