Documentation
¶
Index ¶
- type Cache
- type CacheEntries
- type CachePool
- type InMemoryCacheProvider
- func (provider *InMemoryCacheProvider) Get(key string, t reflect.Type) (interface{}, bool)
- func (provider *InMemoryCacheProvider) Invalidate(key string, t reflect.Type) bool
- func (provider *InMemoryCacheProvider) Shutdown()
- func (provider *InMemoryCacheProvider) Update(key string, t reflect.Type, value interface{}) error
- func (provider *InMemoryCacheProvider) UseGarbageCollector() bool
- type Item
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache holds cache entries and a lock to allow manage concurrent access.
type CacheEntries ¶
CacheEntries is a map that holds cache items.
type CachePool ¶
CachePool holds type specific Cache instances. This structure allows to optimize locking of the cache. As every type has its own Cache instance, the entire CachePool does not need to be locked longer than necessary, as large part of data is in the dedicated Cache instances.
type InMemoryCacheProvider ¶
type InMemoryCacheProvider struct {
// contains filtered or unexported fields
}
InMemoryCacheProvider provides the ability to cache data in the RAM.
func New ¶
func New(lifetime time.Duration) *InMemoryCacheProvider
New creates a new cache with the specified lifetime (in seconds).
func (*InMemoryCacheProvider) Get ¶
func (provider *InMemoryCacheProvider) Get(key string, t reflect.Type) (interface{}, bool)
Get an Item from the cache, if there is a valid one. The function will return nil if there is no valid cache entry. A valid cache entry is present when:
- for the given type and key an item can be found.
- the found items lifetime is not exceeded
func (*InMemoryCacheProvider) Invalidate ¶
func (provider *InMemoryCacheProvider) Invalidate(key string, t reflect.Type) bool
Invalidate manually invalidates the cache item behind the supplied key, if there is a cache item.
func (*InMemoryCacheProvider) Shutdown ¶ added in v0.4.0
func (provider *InMemoryCacheProvider) Shutdown()
Shutdown on in-memory cache does nothing, as no external services are used.
func (*InMemoryCacheProvider) Update ¶
func (provider *InMemoryCacheProvider) Update(key string, t reflect.Type, value interface{}) error
Update adds and item to the cache or updates it.
func (*InMemoryCacheProvider) UseGarbageCollector ¶
func (provider *InMemoryCacheProvider) UseGarbageCollector() bool
UseGarbageCollector configures a periodic job that throws out items from the cache that are invalid, to prevent unnecessary memory usage.
Note that currently there is no method to stop the garbage collector once started. However, this is fine for the applications needs.