Documentation ¶
Overview ¶
Package cache provides simple and extensible cache feature for aah application.
OOTB aah pluggable implementation of cache stores In-memory, Redis and Memcache. Refer to documentation for configuration and usage https://docs.aahframework.org/cache.html
Index ¶
- Variables
- type Cache
- type Config
- type EvictionMode
- type Manager
- func (m *Manager) AddProvider(name string, provider Provider) error
- func (m *Manager) Cache(name string) Cache
- func (m *Manager) CacheNames() []string
- func (m *Manager) CreateCache(cfg *Config) error
- func (m *Manager) InitProviders(appCfg *config.Config, logger log.Loggerer) error
- func (m *Manager) Provider(name string) Provider
- func (m *Manager) ProviderNames() []string
- type Provider
Constants ¶
This section is empty.
Variables ¶
var (
ErrEntryExists = errors.New("aah/cache: entry exists")
)
Cache errors
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // Name method returns the cache store name. Name() string // Get method returns the cached entry for given key if it exists otherwise nil. Get(k string) interface{} // GetOrPut method returns the cached entry for the given key if it exists otherwise // it puts the new entry into cache store and returns the value. GetOrPut(k string, v interface{}, d time.Duration) (interface{}, error) // Put method adds the cache entry with specified expiration. Returns error // if cache entry exists. Put(k string, v interface{}, d time.Duration) error // Delete method deletes the cache entry from cache store. Delete(k string) error // Exists method checks given key exists in cache store and its not expried. Exists(k string) bool // Flush methods flushes(deletes) all the cache entries from cache. Flush() error }
Cache interface represents operation methods for cache store.
type Config ¶
type Config struct { Name string ProviderName string EvictionMode EvictionMode // SweepInterval only applicable to in-memory cache provider. SweepInterval time.Duration }
Config struct represents the cache and cache provider configurations.
type EvictionMode ¶
type EvictionMode uint8
EvictionMode for cache entries.
const ( EvictionModeTTL EvictionMode = 1 + iota EvictionModeNoTTL EvictionModeSlide )
Eviction modes
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager struct represents the aah cache manager.
func (*Manager) AddProvider ¶
AddProvider method adds given provider by name. If provider name exists it return an error otherwise nil.
func (*Manager) CacheNames ¶
CacheNames method returns all cache names from cache manager.
func (*Manager) CreateCache ¶
CreateCache method creates new cache in the cache manager for configuration.
func (*Manager) InitProviders ¶
InitProviders method initializes the cache providers.
func (*Manager) ProviderNames ¶
ProviderNames returns all provider names from cache manager.
type Provider ¶
type Provider interface { // Init method invoked by aah cache manager on application start to initialize cache provider. Init(name string, appCfg *config.Config, logger log.Loggerer) error // Create method invoked by aah cache manager to create cache specific to provider. Create(cfg *Config) (Cache, error) }
Provider interface represents cache provider implementation.