aahframe.work: aahframe.work/cache Index | Files

package cache

import "aahframe.work/cache"

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


Package Files



var (
    ErrEntryExists = errors.New("aah/cache: entry exists")

Cache errors

type Cache Uses

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 Uses

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 Uses

type EvictionMode uint8

EvictionMode for cache entries.

const (
    EvictionModeTTL EvictionMode = 1 + iota

Eviction modes

type Manager Uses

type Manager struct {
    // contains filtered or unexported fields

Manager struct represents the aah cache manager.

func NewManager Uses

func NewManager() *Manager

NewManager method returns new cache Manager.

func (*Manager) AddProvider Uses

func (m *Manager) AddProvider(name string, provider Provider) error

AddProvider method adds given provider by name. If provider name exists it return an error otherwise nil.

func (*Manager) Cache Uses

func (m *Manager) Cache(name string) Cache

Cache method return cache by given name if exists otherwise nil.

func (*Manager) CacheNames Uses

func (m *Manager) CacheNames() []string

CacheNames method returns all cache names from cache manager.

func (*Manager) CreateCache Uses

func (m *Manager) CreateCache(cfg *Config) error

CreateCache method creates new cache in the cache manager for configuration.

func (*Manager) InitProviders Uses

func (m *Manager) InitProviders(appCfg *config.Config, logger log.Loggerer) error

InitProviders method initializes the cache providers.

func (*Manager) Provider Uses

func (m *Manager) Provider(name string) Provider

Provider method returns provider by given name if exists otherwise nil.

func (*Manager) ProviderNames Uses

func (m *Manager) ProviderNames() []string

ProviderNames returns all provider names from cache manager.

type Provider Uses

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.

Package cache imports 6 packages (graph) and is imported by 4 packages. Updated 2019-01-01. Refresh now. Tools for package owners.