Documentation
¶
Index ¶
- Variables
- func Cache(store CacheStore) echo.MiddlewareFunc
- func CacheWithConfig(config CacheConfig) echo.MiddlewareFunc
- type Algorithm
- type CacheConfig
- type CacheMemoryStore
- type CacheMemoryStoreConfig
- type CacheMetrics
- type CacheRedisClusterStore
- type CacheRedisStore
- type CacheResponse
- type CacheStats
- type CacheStore
- func NewCacheRedisClusterStore() CacheStore
- func NewCacheRedisClusterStoreWithConfig(opt redis.ClusterOptions) CacheStore
- func NewCacheRedisStoreWithConfig(opt redis.Options) CacheStore
- func NewCacheTwoLevelStore(l1Store, l2Store CacheStore) CacheStore
- func NewCacheTwoLevelStoreWithConfig(config TwoLevelConfig) CacheStore
- type CacheStrategy
- type CacheTwoLevelStore
- func (store *CacheTwoLevelStore) ClearAll() error
- func (store *CacheTwoLevelStore) ClearL1() error
- func (store *CacheTwoLevelStore) ClearL2() error
- func (store *CacheTwoLevelStore) Get(key uint64) ([]byte, bool)
- func (store *CacheTwoLevelStore) GetStats() CacheStats
- func (store *CacheTwoLevelStore) Release(key uint64)
- func (store *CacheTwoLevelStore) ResetStats()
- func (store *CacheTwoLevelStore) Set(key uint64, response []byte, expiration time.Time)
- func (store *CacheTwoLevelStore) Stop()
- type SyncMode
- type TwoLevelConfig
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultCacheConfig defines default values for CacheConfig DefaultCacheConfig = CacheConfig{ Skipper: middleware.DefaultSkipper, Expiration: 3 * time.Minute, } )
var DefaultCacheMemoryStoreConfig = CacheMemoryStoreConfig{ Capacity: 10, Algorithm: LRU, }
DefaultCacheMemoryStoreConfig provides default configuration values for CacheMemoryStoreConfig
var DefaultTwoLevelConfig = TwoLevelConfig{ Strategy: WriteThrough, L1TTL: 5 * time.Minute, L2TTL: 30 * time.Minute, CacheWarming: true, SyncMode: Async, AsyncBuffer: 1000, }
DefaultTwoLevelConfig provides default configuration
Functions ¶
func Cache ¶
func Cache(store CacheStore) echo.MiddlewareFunc
Cache returns a cache middleware
e := echo.New()
... 추가 설명
func CacheWithConfig ¶
func CacheWithConfig(config CacheConfig) echo.MiddlewareFunc
CacheWithConfig returns a cache middleware
Types ¶
type CacheConfig ¶
type CacheConfig struct { // Skipper defines a function to skip middleware. Skipper middleware.Skipper Store CacheStore Expiration time.Duration // default expiration IncludePaths []string IncludePathsWithExpiration map[string]time.Duration // key: path, value: expiration //IncludePathsWithExpiration has higher priority ExcludePaths []string }
CacheConfig data structure for HTTP cache middleware.
type CacheMemoryStore ¶
type CacheMemoryStore struct {
// contains filtered or unexported fields
}
CacheMemoryStore is the built-in store implementation for Cache
func NewCacheMemoryStore ¶
func NewCacheMemoryStore() (store *CacheMemoryStore)
func NewCacheMemoryStoreWithConfig ¶
func NewCacheMemoryStoreWithConfig(config CacheMemoryStoreConfig) (store *CacheMemoryStore)
func (*CacheMemoryStore) Clear ¶ added in v0.1.0
func (store *CacheMemoryStore) Clear() error
Clear removes all entries from the memory store
func (*CacheMemoryStore) Get ¶
func (store *CacheMemoryStore) Get(key uint64) ([]byte, bool)
Get implements the cache Adapter interface Get method.
func (*CacheMemoryStore) Release ¶
func (store *CacheMemoryStore) Release(key uint64)
Release implements the Adapter interface Release method.
type CacheMemoryStoreConfig ¶
CacheMemoryStoreConfig represents configuration for CacheMemoryStoreConfig
type CacheMetrics ¶ added in v0.1.0
type CacheMetrics struct {
// contains filtered or unexported fields
}
CacheMetrics holds atomic counters for thread-safe statistics
func (*CacheMetrics) GetStats ¶ added in v0.1.0
func (m *CacheMetrics) GetStats() CacheStats
GetStats returns current statistics
func (*CacheMetrics) IncrementL1Hit ¶ added in v0.1.0
func (m *CacheMetrics) IncrementL1Hit()
IncrementL1Hit atomically increments L1 hit counter
func (*CacheMetrics) IncrementL2Hit ¶ added in v0.1.0
func (m *CacheMetrics) IncrementL2Hit()
IncrementL2Hit atomically increments L2 hit counter
func (*CacheMetrics) IncrementMiss ¶ added in v0.1.0
func (m *CacheMetrics) IncrementMiss()
IncrementMiss atomically increments miss counter
func (*CacheMetrics) Reset ¶ added in v0.1.0
func (m *CacheMetrics) Reset()
Reset resets all counters
type CacheRedisClusterStore ¶
type CacheRedisClusterStore struct {
// contains filtered or unexported fields
}
CacheRedisClusterStore is the redis cluster store implementation
func (*CacheRedisClusterStore) Clear ¶ added in v0.1.0
func (store *CacheRedisClusterStore) Clear() error
Clear removes all cache entries from all master nodes
func (*CacheRedisClusterStore) Get ¶
func (store *CacheRedisClusterStore) Get(key uint64) ([]byte, bool)
Get implements the cache CacheRedisClusterStore interface Get method.
func (*CacheRedisClusterStore) Release ¶
func (store *CacheRedisClusterStore) Release(key uint64)
Release implements the cache CacheRedisClusterStore interface Release method.
type CacheRedisStore ¶
type CacheRedisStore struct {
// contains filtered or unexported fields
}
CacheRedisStore is the redis standalone store implementation for Cache
func (*CacheRedisStore) Clear ¶ added in v0.1.0
func (store *CacheRedisStore) Clear() error
Clear removes all entries from the Redis store Note: go-redis/cache library doesn't provide a direct Clear method This is a limitation of the underlying cache library
func (*CacheRedisStore) Get ¶
func (store *CacheRedisStore) Get(key uint64) ([]byte, bool)
Get implements the cache CacheRedisStore interface Get method.
func (*CacheRedisStore) Release ¶
func (store *CacheRedisStore) Release(key uint64)
type CacheResponse ¶
type CacheResponse struct { // URL is URL URL string `json:"url"` // Header is the cached response header. Header http.Header `json:"header"` // Body is the cached response value. Body []byte `json:"body"` // Expiration is the cached response Expiration date. Expiration time.Time `json:"expiration"` // LastAccess is the last date a cached response was accessed. // Used by LRU and MRU algorithms. LastAccess time.Time `json:"lastAccess"` // Frequency is the count of times a cached response is accessed. // Used for LFU and MFU algorithms. Frequency int `json:"frequency"` }
CacheResponse is the cached response data structure.
type CacheStats ¶ added in v0.1.0
type CacheStats struct { L1Hits int64 `json:"l1Hits"` L2Hits int64 `json:"l2Hits"` TotalMiss int64 `json:"totalMiss"` TotalRequest int64 `json:"totalRequest"` HitRate float64 `json:"hitRate"` L1HitRate float64 `json:"l1HitRate"` L2HitRate float64 `json:"l2HitRate"` L1Size int `json:"l1Size"` L2Size int `json:"l2Size"` LastUpdate time.Time `json:"lastUpdate"` }
CacheStats represents cache statistics
type CacheStore ¶
type CacheStore interface { // Get retrieves the cached response by a given key. It also // returns true or false, whether it exists or not. Get(key uint64) ([]byte, bool) // Set caches a response for a given key until an Expiration date. Set(key uint64, response []byte, expiration time.Time) // Release frees cache for a given key. Release(key uint64) }
CacheStore is the interface to be implemented by custom stores.
func NewCacheRedisClusterStore ¶ added in v0.1.0
func NewCacheRedisClusterStore() CacheStore
NewCacheRedisClusterStore creates a new Redis Cluster cache store with default config
func NewCacheRedisClusterStoreWithConfig ¶ added in v0.1.0
func NewCacheRedisClusterStoreWithConfig(opt redis.ClusterOptions) CacheStore
NewCacheRedisClusterStoreWithConfig creates a new Redis Cluster cache store
func NewCacheRedisStoreWithConfig ¶
func NewCacheRedisStoreWithConfig(opt redis.Options) CacheStore
func NewCacheTwoLevelStore ¶ added in v0.1.0
func NewCacheTwoLevelStore(l1Store, l2Store CacheStore) CacheStore
NewCacheTwoLevelStore creates a new two-level cache store with default config
func NewCacheTwoLevelStoreWithConfig ¶ added in v0.1.0
func NewCacheTwoLevelStoreWithConfig(config TwoLevelConfig) CacheStore
NewCacheTwoLevelStoreWithConfig creates a new two-level cache store with custom config
type CacheStrategy ¶ added in v0.1.0
type CacheStrategy string
CacheStrategy defines the caching strategy for two-level cache
const ( // WriteThrough writes to both L1 and L2 synchronously WriteThrough CacheStrategy = "WRITE_THROUGH" // WriteBack writes to L1 first, then L2 asynchronously WriteBack CacheStrategy = "WRITE_BACK" // CacheAside application manages cache explicitly CacheAside CacheStrategy = "CACHE_ASIDE" )
type CacheTwoLevelStore ¶ added in v0.1.0
type CacheTwoLevelStore struct {
// contains filtered or unexported fields
}
CacheTwoLevelStore implements two-level caching with L1 (memory) and L2 (Redis)
func (*CacheTwoLevelStore) ClearAll ¶ added in v0.1.0
func (store *CacheTwoLevelStore) ClearAll() error
ClearAll clears both L1 and L2 caches
func (*CacheTwoLevelStore) ClearL1 ¶ added in v0.1.0
func (store *CacheTwoLevelStore) ClearL1() error
ClearL1 clears only L1 cache
func (*CacheTwoLevelStore) ClearL2 ¶ added in v0.1.0
func (store *CacheTwoLevelStore) ClearL2() error
ClearL2 clears only L2 cache
func (*CacheTwoLevelStore) Get ¶ added in v0.1.0
func (store *CacheTwoLevelStore) Get(key uint64) ([]byte, bool)
Get implements CacheStore interface
func (*CacheTwoLevelStore) GetStats ¶ added in v0.1.0
func (store *CacheTwoLevelStore) GetStats() CacheStats
GetStats returns cache statistics
func (*CacheTwoLevelStore) Release ¶ added in v0.1.0
func (store *CacheTwoLevelStore) Release(key uint64)
Release implements CacheStore interface
func (*CacheTwoLevelStore) ResetStats ¶ added in v0.1.0
func (store *CacheTwoLevelStore) ResetStats()
ResetStats resets cache statistics
func (*CacheTwoLevelStore) Set ¶ added in v0.1.0
func (store *CacheTwoLevelStore) Set(key uint64, response []byte, expiration time.Time)
Set implements CacheStore interface
func (*CacheTwoLevelStore) Stop ¶ added in v0.1.0
func (store *CacheTwoLevelStore) Stop()
Stop gracefully stops the two-level cache store
type TwoLevelConfig ¶ added in v0.1.0
type TwoLevelConfig struct { L1Store CacheStore L2Store CacheStore Strategy CacheStrategy L1TTL time.Duration L2TTL time.Duration CacheWarming bool SyncMode SyncMode AsyncBuffer int // Buffer size for async operations }
TwoLevelConfig represents configuration for TwoLevelStore