memcached

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToEmptyInterface added in v1.4.1

func BytesToEmptyInterface(data []byte) (interface{}, error)

BytesToEmptyInterface converts byte array to interface{} object

func CreateMemCacheObject added in v1.4.1

func CreateMemCacheObject(key string, value interface{}, expiration int32) (*memcache.Item, error)

CreateMemCacheObject creates a *memcache.Item It takes in key, value and expiration time. expiration is the cache expiration time, in seconds: either a relative time from now (up to 1 month), or an absolute Unix epoch time. Zero means the Item has no expiration time. It returns (nil, err) if there's any other error, else returns a *memcache.Item

func GetBytes added in v1.4.1

func GetBytes(key interface{}) ([]byte, error)

GetBytes converts interface{} to a byte array

Types

type CacheClient

type CacheClient struct {
	// contains filtered or unexported fields
}

CacheClient is used to add,update,remove items from memcache

func NewMemCachedClient

func NewMemCachedClient(serverList []string) (*CacheClient, error)

NewMemCachedClient returns a connected client server to cache to. It returns the *CacheClient object if successful, else returns (nil,err)

func (*CacheClient) AddItem added in v1.4.1

func (c *CacheClient) AddItem(key string, value interface{}, expiration int32) (bool, error)

AddItem saves an Item to cache. It returns false,error if it is unable to save the Item. expiration is the cache expiration time, in seconds: either a relative time from now (up to 1 month), or an absolute Unix epoch time. Zero means the Item has no expiration time.

func (*CacheClient) DeleteItem added in v1.4.1

func (c *CacheClient) DeleteItem(key string) (bool, error)

DeleteItem deletes a given key from the server after a 5 mins delay. It returns false, error if the operation was unsuccessful. key is the memcache key to be deleted.

func (*CacheClient) DeleteWithoutDelay added in v1.4.1

func (c *CacheClient) DeleteWithoutDelay(key string) (bool, error)

DeleteWithoutDelay deletes a given key from the server without any delay It returns false,error if delete was unsuccessful.

func (*CacheClient) DoesKeyExist added in v1.7.3

func (c *CacheClient) DoesKeyExist(key string) (bool, error)

Checks whether a key exists in memcache It returns true if key exists and returns false if key not found

func (*CacheClient) GetItem added in v1.4.1

func (c *CacheClient) GetItem(key string, expiration int32, dbCallBack func() (interface{}, error)) (interface{}, error)

GetItem takes in the key, expiration and a dbCallBack function. If a cache miss occurs, the dbCallBack function is called which retrieves data from the database. This value from the database is saved back to memcache. expiration is the cache expiration time, in seconds: either a relative time from now (up to 1 month), or an absolute Unix epoch time. Zero means the Item has no expiration time. It returns (nil, err) if there's any other error, else returns an interface{} object.

func (*CacheClient) UpdateItem added in v1.4.1

func (c *CacheClient) UpdateItem(key string, value interface{}, expiration int32, addIfNotExists bool) (bool, error)

UpdateItem updates an Item in cache. If addIfNotExists is true, the item is added if the key doesn't exist. It returns error if it is unable to update the Item. expiration is the cache expiration time, in seconds: either a relative time from now (up to 1 month), or an absolute Unix epoch time. Zero means the Item has no expiration time.

Jump to

Keyboard shortcuts

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