v0.12.5 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 6 Imported by: 3



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



This section is empty.


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

Cache errors


This section is empty.


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

Eviction modes

type Manager

type Manager struct {
	// contains filtered or unexported fields

Manager struct represents the aah cache manager.

func NewManager

func NewManager() *Manager

NewManager method returns new cache Manager.

func (*Manager) AddProvider

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

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

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

func (*Manager) CacheNames

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

CacheNames method returns all cache names from cache manager.

func (*Manager) CreateCache

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

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

func (*Manager) InitProviders

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

InitProviders method initializes the cache providers.

func (*Manager) Provider

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

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

func (*Manager) ProviderNames

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

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.


Path Synopsis
inmemory Module
memcache Module
redis Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL