Documentation
¶
Index ¶
- func InjectResults(r []Result, out interface{})
- type Builder
- type Cache
- func (c *Cache) Delete(ctx context.Context, key string) error
- func (c *Cache) DeleteValue(ctx context.Context, value interface{}) error
- func (c *Cache) Get(ctx context.Context, key interface{}) (Result, error)
- func (c *Cache) GetMulti(ctx context.Context, keys []interface{}) ([]Result, error)
- func (c *Cache) Set(ctx context.Context, value interface{}) error
- type CacheStore
- type CachedRepository
- type DataFetcher
- type DataWriter
- type EmptyResult
- type Handler
- type NonUniqueKeyCacheDefinition
- type ReadOnlyCachedRepository
- type Result
- type UniqueKeyCacheDefinition
- type ValueResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InjectResults ¶
func InjectResults(r []Result, out interface{})
Types ¶
type Builder ¶
type Builder interface { // Adds a new Unique Key cache to the builder. // // Unique Key caches are used when a key in the cache refers to a single element. // For example, when the cache key represents a Primary Key of a database table. WithUniqueKeyCache(cacheDefinition UniqueKeyCacheDefinition, store CacheStore) Builder // Adds a new Non-Unique Key cache to the builder. // // Non-Unique Key caches are used when a key in the cache can hold more than one element. // For example, when the cache key represents a Foreign Key of a database table. // // Non-Unique caches require a subKey to be defined to compare the multiple elements inside a single cache // key entry. WithNonUniqueKeyCache(cacheDefinition NonUniqueKeyCacheDefinition, store CacheStore) Builder // Data Fetcher to use when retrieving data by a field considered a unique key WithUniqueKeyDataFetcher(fetcher DataFetcher) Builder // Data Fetcher to use when retrieving data by a field considered a non-unique key WithNonUniqueKeyDataFetcher(fetcher DataFetcher) Builder // DataWriter to be used when new data needs to be stored in a repository WithDataWriter(writer DataWriter) Builder // Indicates if the cache entries should be evicted entries after data is written to the repository // or if data in the cache should be updated instead EvictAfterWrite(v bool) Builder // Creates a new CachedRepository // // This method panics if it can't create the CachedRepository BuildCachedRepository() CachedRepository // Creates a new ReadOnlyCachedRepository. // // This method panics if it can't create the ReadOnlyCachedRepository BuildROCachedRepository() ReadOnlyCachedRepository }
Defines a new Builder used to create a new CachedRepository
func CachedRepositoryBuilder ¶
func CachedRepositoryBuilder(dataType interface{}) Builder
type Cache ¶
type Cache struct { Handler Handler Store CacheStore DataFetcher DataFetcher }
func (*Cache) DeleteValue ¶
type CacheStore ¶
type CacheStore interface { // Deletes the provided key from the cache Delete(ctx context.Context, key string) error // Retrieves the provided key from the cache and places the output value in the out variable // // The type of out is expected to be a pointer to the element being stored, for example, if we're // storing elements of type A, then out is expected to be of type *A Get(ctx context.Context, key string, out interface{}) (bool, error) // Retrieves the provided key from the cache and places the output value in the out variable // // The type of out is expected to be a pointer to a slice of pointers of the elements being stored, // for example, if we're storing elements of type A, then out is expected to be of type *[]*A GetMulti(ctx context.Context, keys []string, out interface{}) ([]bool, error) // Sets the key in the cache with the provided value Set(ctx context.Context, key string, value interface{}, expiration time.Duration) }
type CachedRepository ¶
type CachedRepository interface { ReadOnlyCachedRepository // Inserts the provided value into the repository // // If successful, then the value is also cached in the configured caches and/or evicted // from the caches that requested eviction on write operations Create(ctx context.Context, value interface{}) error // Updates the provided value in the repository // // If successful, then the value is also updated/cached in the configured caches and/or evicted // from the caches that requested eviction on write operations Update(ctx context.Context, value interface{}) error //Updates partially the provided value in the repository // // If successful, then the value is also updated/cached in the configured caches and/or evicted // Also fully updated object will be retrieved from data storage and will be cached // value param works as in/out: full object, retrieved from database after update, will be stored in this variable // from the caches that requested eviction on write operations PartialUpdate(ctx context.Context, value interface{}) error }
type DataFetcher ¶
type DataWriter ¶
type DataWriter interface { // Inserts the provided value into the repository Create(ctx context.Context, value interface{}) error // Updates the provided value in the repository Update(ctx context.Context, value interface{}) error // Updates the provided value in the repository partially changing only received fields PartialUpdate(ctx context.Context, value interface{}) error }
type EmptyResult ¶
type EmptyResult struct { }
func (EmptyResult) InjectResult ¶
func (e EmptyResult) InjectResult(out interface{})
func (EmptyResult) IsEmpty ¶
func (e EmptyResult) IsEmpty() bool
func (EmptyResult) StoredValue ¶
func (e EmptyResult) StoredValue() interface{}
type Handler ¶
type Handler interface { Delete(ctx context.Context, cacheStore CacheStore, key interface{}) error DeleteValue(ctx context.Context, cacheStore CacheStore, value interface{}) error Get(ctx context.Context, cacheStore CacheStore, key interface{}, fetcher DataFetcher) (Result, error) GetMulti(ctx context.Context, cacheStore CacheStore, keys []interface{}, fetcher DataFetcher) ([]Result, error) Set(ctx context.Context, cacheStore CacheStore, value interface{}) error CachedType() reflect.Type CacheKeyPrefix() string SingleResultPerKey() bool }
this interface is for internal use only - users of the library shouldn't need to implement this interface
func NonUniqueKeyCache ¶
func NonUniqueKeyCache(v interface{}, cacheDef NonUniqueKeyCacheDefinition) Handler
func UniqueKeyCache ¶
func UniqueKeyCache(v interface{}, cacheDefinition UniqueKeyCacheDefinition) Handler
type NonUniqueKeyCacheDefinition ¶
type NonUniqueKeyCacheDefinition struct { KeyPrefix string // Name of the field that defines the key that will be used to store elements in the cache KeyFieldName string // Name of the field that defines the subkey that will be used to compare and store elements that // belong to the same key SubKeyFieldName string // Expiration time of entries in the cache Expiration time.Duration // Indicates if empty results should be cached CacheEmptyResults bool }
type ReadOnlyCachedRepository ¶
type ReadOnlyCachedRepository interface { // Retrieves the data from the repository using the given keyFieldName for the given id value. // // - If the keyFieldName is a Unique Key of the entity, then the result will be a single element. // // - If the keyFieldName is not a Unique Key of the entity, then the result will be a slice of elements. FindByKey(ctx context.Context, keyFieldName string, id interface{}) (Result, error) // Retrieves the data from the repository using the given keyFieldName for the given ids. // // - If the keyFieldName is a Unique Key of the entity, then the result will be a single element per id. // // - If the keyFieldName is not a Unique Key of the entity, then the result will be a slice of elements per id. // // Each element in the returned slice corresponds to an id, that is, the result in position 0 corresponds to // the id in position 0 // // Ids is expected to be a pointer to a slice or a slice of the corresponding type stored in the keyFieldName, // for example, if the keyFieldName stores strings, then ids is expected to be of type *[]string or []string FindByKeys(ctx context.Context, keyFieldName string, ids interface{}) ([]Result, error) }
type Result ¶
type Result interface { IsEmpty() bool InjectResult(out interface{}) StoredValue() interface{} }
type ValueResult ¶
type ValueResult struct {
Value interface{}
}
func (ValueResult) InjectResult ¶
func (r ValueResult) InjectResult(out interface{})
func (ValueResult) IsEmpty ¶
func (r ValueResult) IsEmpty() bool
func (ValueResult) StoredValue ¶
func (r ValueResult) StoredValue() interface{}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.