cachemanager

package
v0.0.0-...-0686167 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// TypeCache indicates fast cache as cache storage
	TypeCache = iota + 1
	TypeRedisCache
)

Variables

This section is empty.

Functions

func RedisWithAddr

func RedisWithAddr(addr string) redisOption

func RedisWithDB

func RedisWithDB(db int) redisOption

func RedisWithExpiration

func RedisWithExpiration(exp time.Duration) redisOption

func RedisWithPassword

func RedisWithPassword(p string) redisOption

func RedisWithPrefix

func RedisWithPrefix(pfx string) redisOption

func WithCleanupInterval

func WithCleanupInterval(ivl time.Duration) cacheOption

WithCleanupInterval returns the expired items clean up time

func WithExpiration

func WithExpiration(exp time.Duration) cacheOption

WithExpiration returns the expiration time

func WithMaxEntries

func WithMaxEntries(i int) cacheOption

WithMaxEntries returns the MaxEntries that can be accepted

Types

type Cache

type Cache interface {
	// Setters
	Set(key string, val interface{})
	SetWithExpiration(key string, val interface{}, exp time.Duration)
	SetNoExpiration(key string, val interface{})
	SaveFile(fname string)
	// Getters
	Get(key string) (interface{}, bool)
	GetAll() map[string]interface{}
	LoadFile(fname string)

	// Deletion operations
	Delete(key string)
	Purge()

	// GetItemsCount
	GetItemsCount() int

	Type() int
}

Cache provides access to underlying cache, make sure all caches implement these methods.

type CacheHelper

type CacheHelper struct {
	Cache       *cache.Cache
	Expiration  time.Duration
	CleanupTime time.Duration
	MaxEntries  int
}

CacheHelper is a struct

func SetupCache

func SetupCache(opts ...cacheOption) *CacheHelper

SetupCache initializes fastcache cache for application and returns its instance.

func (*CacheHelper) Delete

func (cacheHelper *CacheHelper) Delete(key string)

Delete -

func (*CacheHelper) Get

func (cacheHelper *CacheHelper) Get(key string) (interface{}, bool)

Get -

func (*CacheHelper) GetAll

func (cacheHelper *CacheHelper) GetAll() map[string]interface{}

GetAll returns all keys with values present in memory. **This is not intended for production use. May hamper performance**

func (*CacheHelper) GetItems

func (cacheHelper *CacheHelper) GetItems() map[string]cache.Item

GetItems -

func (*CacheHelper) GetItemsCount

func (cacheHelper *CacheHelper) GetItemsCount() int

GetItemsCount : Number of items in the cache

func (*CacheHelper) LoadFile

func (cacheHelper *CacheHelper) LoadFile(fname string) error

LoadFile to load saved file

func (*CacheHelper) Purge

func (cacheHelper *CacheHelper) Purge()

Purge -

func (*CacheHelper) SaveFile

func (cacheHelper *CacheHelper) SaveFile(fname string) error

SaveFile is the

func (*CacheHelper) Set

func (cacheHelper *CacheHelper) Set(key string, object interface{})

Set -

func (*CacheHelper) SetNoExpiration

func (cacheHelper *CacheHelper) SetNoExpiration(key string, object interface{})

SetNoExpiration -

func (*CacheHelper) SetWithExpiration

func (cacheHelper *CacheHelper) SetWithExpiration(key string, object interface{}, duration time.Duration)

SetWithExpiration -

func (*CacheHelper) Setup

func (cacheHelper *CacheHelper) Setup(maxEntries int, expiration time.Duration, cleanupTime time.Duration)

Setup initializes fastcache cache for application. Must be called only once.

func (*CacheHelper) Type

func (cacheHelper *CacheHelper) Type() int

Type returns the cache type

type RedisCache

type RedisCache struct {
	Addr       string        // redis server address, default "127.0.0.1:6379"
	DB         int           // redis DB on provided server, default 0
	Password   string        //
	Expiration time.Duration // this duration will be used for Set() method
	Prefix     string        // this will be used for storing keys for provided project
	// contains filtered or unexported fields
}

RedisCache represents a Redis client with provided configuration. Do not change configuration at runtime.

func SetupRedisCache

func SetupRedisCache(opts ...redisOption) (*RedisCache, error)

SetupRedisCache initializes redis cache for application and returns it. Must be called only once.

func (*RedisCache) Delete

func (rc *RedisCache) Delete(key string)

Delete -

func (*RedisCache) Get

func (rc *RedisCache) Get(key string) (interface{}, bool)

Get returns data against provided key. Returns false if not present.

func (*RedisCache) GetAll

func (rc *RedisCache) GetAll() map[string]interface{}

GetAll returns all keys with values present in redis server. Excludes the keys which does not have specified prefix. If prefix is empty, then returns all keys.

**This is not intended for production use. May hamper performance**

func (*RedisCache) GetItemsCount

func (rc *RedisCache) GetItemsCount() int

GetItemsCount -

func (*RedisCache) Purge

func (rc *RedisCache) Purge()

Purge deletes for current redis db

func (*RedisCache) Set

func (rc *RedisCache) Set(key string, val interface{})

Set marshalls provided value and stores against provided key. Errors will be logged to initialized logger.

func (*RedisCache) SetNoExpiration

func (rc *RedisCache) SetNoExpiration(key string, val interface{})

SetNoExpiration marshalls provided value and stores against provided key. Errors will be logged to initialized logger.

func (*RedisCache) SetWithExpiration

func (rc *RedisCache) SetWithExpiration(key string, val interface{}, exp time.Duration)

SetWithExpiration marshalls provided value and stores against provided key for given duration. Errors will be logged to initialized logger.

func (*RedisCache) Setup

func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Duration)

Setup initializes redis cache for application. Must be called only once.

func (*RedisCache) Type

func (rc *RedisCache) Type() int

Jump to

Keyboard shortcuts

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