Documentation
¶
Index ¶
- Variables
- type Asserter
- type Cache
- func (c *Cache) Close() error
- func (c *Cache) Delete(key string) error
- func (c *Cache) Get(key string) interface{}
- func (c *Cache) Lookup(key string) (interface{}, bool)
- func (c *Cache) NoExpiration()
- func (c *Cache) Set(key string, value interface{}) error
- func (c *Cache) UseExpiration()
- func (c *Cache) WithExpiration() bool
- type Caller
- type Checker
- type GetSetter
- type Getter
- type Kind
- type OS
- type RPC
- func (r *RPC) Available() bool
- func (r *RPC) Bulk(batch map[string]interface{}) error
- func (r *RPC) Clear() error
- func (r *RPC) Close() error
- func (r *RPC) Delete(key string) error
- func (r *RPC) Get(key string) interface{}
- func (r *RPC) Lookup(key string) (interface{}, bool)
- func (r *RPC) Raw(key string) (interface{}, error)
- func (r *RPC) Set(key string, value interface{}) error
- func (r *RPC) Stats() (*cache.Metrics, error)
- type Setter
Constants ¶
This section is empty.
Variables ¶
var ( ErrConn = errors.New("missing connection") ErrFailure = errors.New("request has failed") ErrKind = errors.New("invalid data type") )
Error messages.
var DefaultCacheDuration = 15 * time.Minute
DefaultCacheDuration is the default duration to keep data in cache.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache represents the service to access data as a memory cache.
func NewCache ¶
NewCache returns a new instance of the cache and starts the recycler. The Close method must be called to properly close the recycler and avoids leaks.
func (*Cache) Lookup ¶
Lookup returns the value behind the key in cache. If the key is not found, the boolean is false.
func (*Cache) NoExpiration ¶
func (c *Cache) NoExpiration()
NoExpiration deactivates the item's expiration.
func (*Cache) Set ¶
Set puts the value in cache with an expiration date fixed by the cache duration.
func (*Cache) UseExpiration ¶
func (c *Cache) UseExpiration()
UseExpiration reactivates the item's expiration.
func (*Cache) WithExpiration ¶
WithExpiration returns true if the data expiration is enabled.
type Caller ¶
Caller must be implemented by any client to call a service, waits for it to complete, and returns its error status.
type Checker ¶
type Checker interface {
Available() bool
}
Checker must be implemented by any client to notify its availability.
type OS ¶
type OS struct{}
OS is the client to get environment variable from operating system.
func (*OS) Assert ¶
Assert tries to cast the value with the given data kind. If success, it returns the data typed and true as ok value.
type RPC ¶
type RPC struct {
// contains filtered or unexported fields
}
RPC is client with connection to cache'service.
func NewRPC ¶
NewRPC returns a new instance of RPC. This instance has no mechanism to reconnect on failure.
func OpenRPC ¶
OpenRPC returns an instance of RPC with a TCP connection into it. DSN is in the form of "localhost:9090". If the connection fails, it returns the error. Unlike NewRPC, OpenRPC has an internal mechanism to reconnect on failure.
func (*RPC) Bulk ¶
Bulk applies the item modifications on the cache. It acknowledges the boolean if it succeeds. An error occurs if the call fails.
func (*RPC) Clear ¶
Clear resets the cache and acknowledges the boolean if it succeeds. An error occurs if the call fails.
func (*RPC) Delete ¶
Delete removes this key in the cache and acknowledges the boolean if it succeeds. An error occurs if the call fails.
func (*RPC) Lookup ¶
Lookup gets the value of the environment variable named by the key. If the variable is present in the environment, the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.