-
Notifications
You must be signed in to change notification settings - Fork 6
/
cache.go
41 lines (31 loc) · 978 Bytes
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package rproxymod
import (
"time"
)
// Statitics about cache usage.
type CacheStats struct {
CacheHitsCount int64
CacheMissesCount int64
CacheErrorCount int64
}
// CacheFetcher is used by the cache to retrieve a value for a key after a cache miss.
type CacheFetcher interface {
Fetch(key []byte) (value []byte, ttl time.Duration, err error)
}
// Cache defines the interface of a cache the reverse proxy can use to cache cross-request information.
type Cache interface {
// Set a cache value, potentially with a TTL
Set(key []byte, value []byte, ttl time.Duration) error
// Get the value of a key
Get(key []byte) (value []byte, err error)
// Get a value and fetch it in case of cache miss.
GetAndStore(key []byte, fetcher CacheFetcher) (value []byte, err error)
// Delete a key from the cache
Delete(key []byte)
// Clear the cache
Clear()
// Close the cache
Close() error
// Get statistics about cache usage.
GetCacheStats() (stats *CacheStats)
}