Documentation ¶
Overview ¶
Package multicacheadapters contains the implementations of CacheAdapter and CacheSessionAdapter with the objective of accessing multiple cache sources with fallback support.
Just use this adapter and when a cache source errors, it will automatically perform the operations on other sources.
Index ¶
- Variables
- type MultiCacheAdapter
- func (mca *MultiCacheAdapter) Delete(key string) error
- func (mca *MultiCacheAdapter) DisableWarnings()
- func (mca *MultiCacheAdapter) EnableWarnings()
- func (mca *MultiCacheAdapter) Get(key string, objectRef interface{}) error
- func (mca *MultiCacheAdapter) OpenSession() (cacheadapters.CacheSessionAdapter, error)
- func (mca *MultiCacheAdapter) Set(key string, object interface{}, TTL *time.Duration) error
- func (mca *MultiCacheAdapter) SetTTL(key string, newTTL time.Duration) error
- type MultiCacheSessionAdapter
- func (mcsa *MultiCacheSessionAdapter) Close() error
- func (mcsa *MultiCacheSessionAdapter) Delete(key string) error
- func (mcsa *MultiCacheSessionAdapter) DisableWarnings()
- func (mcsa *MultiCacheSessionAdapter) EnableWarnings()
- func (mcsa *MultiCacheSessionAdapter) Get(key string, objectRef interface{}) error
- func (mcsa *MultiCacheSessionAdapter) Set(key string, object interface{}, TTL *time.Duration) error
- func (mcsa *MultiCacheSessionAdapter) SetTTL(key string, newTTL time.Duration) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidSubAdapters will come out if you try to pass one or more nil // sub-adapters when creating a new MultiCacheAdapter or a session. ErrInvalidSubAdapters = fmt.Errorf("you must pass at least one valid sub-adapter") // ErrMultiCacheWarning will come out paired with other errors in case // an non-fatal error occurs during a multicache operation. // // This includes for example when a GET operation fails on the first // adapter but is successful in the second adapter. ErrMultiCacheWarning = fmt.Errorf("warning when performing an operation with a multicache adapter") )
Functions ¶
This section is empty.
Types ¶
type MultiCacheAdapter ¶
type MultiCacheAdapter struct {
// contains filtered or unexported fields
}
MultiCacheAdapter is a cache adapter which uses multiple sub-adapters, following a priority given by the index of the adapter in the inner array of adapters.
func New ¶
func New(adapters ...cacheadapters.CacheAdapter) (*MultiCacheAdapter, error)
New creates a new multi cache adapter from an index-based priority array of cache adapters (called sub-adapters) and a flag instructing to show warning (non-fatal) errors.
index-based means that the array at the first position(s) will have more priority than those at latter positions.
func (*MultiCacheAdapter) Delete ¶
func (mca *MultiCacheAdapter) Delete(key string) error
Delete deletes a key from the cache.
func (*MultiCacheAdapter) DisableWarnings ¶
func (mca *MultiCacheAdapter) DisableWarnings()
DisableWarning disables the return of warning errors.
If the error is a warning, you can continue standard execution as The operations concluded successfully. You can then log the warning using your favourite tool (like sentry).
Warning errors, if shown need different handling from traditional errors. Use the helper IsWarning(error err) to check for warnings.
Example of handling of warnings:
err := adapter.Get("key", &objRef) if (errors.Is(cacheadapter.ErrWarning)) { // log the error, but use objRef safely } else if err != nil { // log the error and handle a failure // you cannot use objRef safely here } // else use objRef safely without any error
func (*MultiCacheAdapter) EnableWarnings ¶
func (mca *MultiCacheAdapter) EnableWarnings()
EnableWarning enable the return of warning errors.
If the error is a warning, you can continue standard execution as The operations concluded successfully. You can then log the warning using your favourite tool (like sentry).
Warning errors, if shown need different handling from traditional errors. Use the helper IsWarning(error err) to check for warnings.
Example of handling of warnings:
err := adapter.Get("key", &objRef) if (cacheadapters.IsWarning(err)) { // log the error, but use objRef safely } else if err != nil { // log the error and handle a failure // you cannot use objRef safely here } // else use objRef safely without any error
func (*MultiCacheAdapter) Get ¶
func (mca *MultiCacheAdapter) Get(key string, objectRef interface{}) error
Get obtains a value from the cache using a key, then tries to unmarshal it into the object reference passed as parameter.
func (*MultiCacheAdapter) OpenSession ¶
func (mca *MultiCacheAdapter) OpenSession() (cacheadapters.CacheSessionAdapter, error)
type MultiCacheSessionAdapter ¶
type MultiCacheSessionAdapter struct {
// contains filtered or unexported fields
}
MultiCacheSessionAdapter is a cache adapter which uses multiple sub-adapters, following a priority given by the index of the adapter in the inner array of adapters.
func NewSession ¶
func NewSession(adapters ...cacheadapters.CacheSessionAdapter) (*MultiCacheSessionAdapter, error)
NewSession creates a new multi cache session adapter from an index-based priority array of cache adapters (called sub-adapters) and a flag instructing to show warning (non-fatal) errors.
index-based means that the array at the first position(s) will have more priority than those at latter positions.
func (*MultiCacheSessionAdapter) Close ¶
func (mcsa *MultiCacheSessionAdapter) Close() error
Close closes the Cache Sessions.
func (*MultiCacheSessionAdapter) Delete ¶
func (mcsa *MultiCacheSessionAdapter) Delete(key string) error
Delete deletes a key from the cache.
func (*MultiCacheSessionAdapter) DisableWarnings ¶
func (mcsa *MultiCacheSessionAdapter) DisableWarnings()
DisableWarning disables the return of warning errors.
If the error is a warning, you can continue standard execution as The operations concluded successfully. You can then log the warning using your favourite tool (like sentry).
Warning errors, if shown need different handling from traditional errors. Use the helper IsWarning(error err) to check for warnings.
Example of handling of warnings:
err := adapter.Get("key", &objRef) if (errors.Is(cacheadapter.ErrWarning)) { // log the error, but use objRef safely } else if err != nil { // log the error and handle a failure // you cannot use objRef safely here } // else use objRef safely without any error
func (*MultiCacheSessionAdapter) EnableWarnings ¶
func (mcsa *MultiCacheSessionAdapter) EnableWarnings()
EnableWarning enable the return of warning errors.
If the error is a warning, you can continue standard execution as The operations concluded successfully. You can then log the warning using your favourite tool (like sentry).
Warning errors, if shown need different handling from traditional errors. Use the helper IsWarning(error err) to check for warnings.
Example of handling of warnings:
err := adapter.Get("key", &objRef) if (cacheadapters.IsWarning(err)) { // log the error, but use objRef safely } else if err != nil { // log the error and handle a failure // you cannot use objRef safely here } // else use objRef safely without any error
func (*MultiCacheSessionAdapter) Get ¶
func (mcsa *MultiCacheSessionAdapter) Get(key string, objectRef interface{}) error
Get obtains a value from the cache using a key, then tries to unmarshal it into the object reference passed as parameter.