cache

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigContent          ConfigCachedFileType = "Config Content"
	ConfigEncryptedDataKey ConfigCachedFileType = "Config Encrypted Data Key"

	ENCRYPTED_DATA_KEY_FILE_NAME = "encrypted-data-key"
	FAILOVER_FILE_SUFFIX         = "_failover"
)

Variables

View Source
var SHARD_COUNT = 32

Functions

func GetConfigEncryptedDataKeyFileName added in v1.2.5

func GetConfigEncryptedDataKeyFileName(cacheKey, cacheDir string) string

func GetConfigFailOverContentFileName added in v1.2.5

func GetConfigFailOverContentFileName(cacheKey, cacheDir string) string

func GetConfigFailOverEncryptedDataKeyFileName added in v1.2.5

func GetConfigFailOverEncryptedDataKeyFileName(cacheKey, cacheDir string) string

func GetEncryptedDataKeyDir added in v1.2.5

func GetEncryptedDataKeyDir(cacheDir string) string

func GetFailover added in v1.2.5

func GetFailover(key, dir string) string

GetFailover , get failover content

func GetFailoverEncryptedDataKey added in v1.2.5

func GetFailoverEncryptedDataKey(key, dir string) string

func GetFileName

func GetFileName(cacheKey, cacheDir string) string

func ReadConfigFromFile

func ReadConfigFromFile(cacheKey string, cacheDir string) (string, error)

func ReadEncryptedDataKeyFromFile added in v1.2.5

func ReadEncryptedDataKeyFromFile(cacheKey string, cacheDir string) (string, error)

func ReadServicesFromFile

func ReadServicesFromFile(cacheDir string) map[string]model.Service

func WriteConfigToFile

func WriteConfigToFile(cacheKey string, cacheDir string, content string) error

func WriteEncryptedDataKeyToFile added in v1.2.5

func WriteEncryptedDataKeyToFile(cacheKey string, cacheDir string, content string) error

func WriteServicesToFile

func WriteServicesToFile(service *model.Service, cacheKey, cacheDir string)

Types

type ConcurrentMap

type ConcurrentMap []*ConcurrentMapShared

A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (SHARD_COUNT) map shards.

func NewConcurrentMap

func NewConcurrentMap() ConcurrentMap

Creates a new concurrent map.

func (ConcurrentMap) Count

func (m ConcurrentMap) Count() int

Returns the number of elements within the map.

func (ConcurrentMap) Get

func (m ConcurrentMap) Get(key string) (interface{}, bool)

Retrieves an element from map under given key.

func (ConcurrentMap) GetShard

func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared

Returns shard under given key

func (ConcurrentMap) Has

func (m ConcurrentMap) Has(key string) bool

Looks up an item under specified key

func (ConcurrentMap) IsEmpty

func (m ConcurrentMap) IsEmpty() bool

Checks if map is empty.

func (ConcurrentMap) Items

func (m ConcurrentMap) Items() map[string]interface{}

Returns all items as map[string]interface{}

func (ConcurrentMap) Iter deprecated

func (m ConcurrentMap) Iter() <-chan Tuple

Returns an iterator which could be used in a for range loop.

Deprecated: using IterBuffered() will get a better performence

func (ConcurrentMap) IterBuffered

func (m ConcurrentMap) IterBuffered() <-chan Tuple

Returns a buffered iterator which could be used in a for range loop.

func (ConcurrentMap) IterCb

func (m ConcurrentMap) IterCb(fn IterCb)

Callback based iterator, cheapest way to read all elements in a map.

func (ConcurrentMap) Keys

func (m ConcurrentMap) Keys() []string

Return all keys as []string

func (ConcurrentMap) MSet

func (m ConcurrentMap) MSet(data map[string]interface{})

func (ConcurrentMap) MarshalJSON

func (m ConcurrentMap) MarshalJSON() ([]byte, error)

Reviles ConcurrentMap "private" variables to json marshal.

func (ConcurrentMap) Pop

func (m ConcurrentMap) Pop(key string) (v interface{}, exists bool)

Removes an element from the map and returns it

func (ConcurrentMap) Remove

func (m ConcurrentMap) Remove(key string)

Removes an element from the map.

func (ConcurrentMap) Set

func (m ConcurrentMap) Set(key string, value interface{})

Sets the given value under the specified key.

func (ConcurrentMap) SetIfAbsent

func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool

Sets the given value under the specified key if no value was associated with it.

func (ConcurrentMap) Upsert

func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{})

Insert or Update - updates existing element or inserts a new one using UpsertCb

type ConcurrentMapShared

type ConcurrentMapShared struct {
	sync.RWMutex // Read Write mutex, guards access to internal map.
	// contains filtered or unexported fields
}

A "thread" safe string to anything map.

type ConfigCachedFileType added in v1.2.5

type ConfigCachedFileType string

type IterCb

type IterCb func(key string, v interface{})

Iterator callback,called for every key,value found in maps. RLock is held for all calls for a given shard therefore callback sess consistent view of a shard, but not across the shards

type Tuple

type Tuple struct {
	Key string
	Val interface{}
}

Used by the Iter & IterBuffered functions to wrap two variables together over a channel,

type UpsertCb

type UpsertCb func(exist bool, valueInMap interface{}, newValue interface{}) interface{}

Callback to return new element to be inserted into the map It is called while lock is held, therefore it MUST NOT try to access other keys in same map, as it can lead to deadlock since Go sync.RWLock is not reentrant

Jump to

Keyboard shortcuts

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