You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for now, all cache implement CacheInterface, but some cache is using CacheInterface:
could I understand this as the Decorator pattern ?
// LoadableCache represents a cache that uses a function to load datatypeLoadableCachestruct {
loadFuncloadFunctioncacheCacheInterfacesetChannelchan*loadableKeyValue
}
// Marshaler is the struct that marshal and unmarshal cache valuestypeMarshalerstruct {
cache cache.CacheInterface
}
AND StoreInterface is same to CacheInterface,
// CacheInterface represents the interface for all caches (aggregates, metric, memory, redis, ...)typeCacheInterfaceinterface {
Get(keyinterface{}) (interface{}, error)
Set(key, objectinterface{}, options*store.Options) errorDelete(keyinterface{}) errorInvalidate(options store.InvalidateOptions) errorClear() errorGetType() string
}
// StoreInterface is the interface for all available storestypeStoreInterfaceinterface {
Get(keyinterface{}) (interface{}, error)
Set(keyinterface{}, valueinterface{}, options*Options) errorDelete(keyinterface{}) errorInvalidate(optionsInvalidateOptions) errorClear() errorGetType() string
}
according to the above case, there is my thoughts:
all cache implement CacheInterface, all store implement StoreInterface, this is good, but the two interface should be different (CacheInterface is an wrapper of StoreInterface, but provide extern functions like: "metrics, loadable, chain and others"), I would change CacheInterface as:
// CacheInterface represents the interface for all caches (aggregates, metric, memory, redis, ...)typeCacheInterfaceinterface {
Get(keyinterface{}) (interface{}, error)
Set(key, objectinterface{}, options*store.Options) errorDelete(keyinterface{}) errorInvalidate(options store.InvalidateOptions) errorClear() errorGetType() string// return cache typeGetCodec() codec.CodecInterface{} // get codec instanceGetStore() store.StoreInterface{} // get current store instance
}
all cache constructor should return CacheInterface to limit usage.
I also think about extern functions, Could we coding them as WithLoadFunc()WithMetrics()WithChain()
typeOptionstruct {
marshal mashaler.MarshalerInterface// ... other fields
}
funcWithMarshal(params...string) *Option {
// do something
}
funcNewCache(store store.StoreInterface, opts...*Options) CacheInterface {
// to construct a Cache
}
I hope this image can help to understand me ~~~
The text was updated successfully, but these errors were encountered:
yeqown
changed the title
I want know why not this arch ?
Here is some thoughts ~
Jun 24, 2020
for now, all cache implement
CacheInterface
, but some cache is usingCacheInterface
:could I understand this as the
Decorator pattern
?AND
StoreInterface
is same toCacheInterface
,according to the above case, there is my thoughts:
CacheInterface
, all store implementStoreInterface
, this is good, but the two interface should be different (CacheInterface
is an wrapper ofStoreInterface
, but provide extern functions like: "metrics, loadable, chain and others"), I would changeCacheInterface
as:all cache constructor should return
CacheInterface
to limit usage.I also think about
extern functions
, Could we coding them asWithLoadFunc()
WithMetrics()
WithChain()
I hope this image can help to understand me ~~~
The text was updated successfully, but these errors were encountered: