Documentation ¶
Overview ¶
Package cache implements DNS response cache.
Index ¶
Examples ¶
Constants ¶
View Source
const URLEnvironmentVariable = "REDIS_URL"
URLEnvironmentVariable is the name of the environment variable containing the Redis URL.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a DNS response cache.
func (*Cache) Get ¶
Get returns a cached DNS response, or nil.
Example ¶
cache, err := OpenCache(&MemoryBackend{}) if err != nil { panic(err) } cache.Set(context.Background(), "wikipedia.org", dnsmessage.TypeA, []byte{1, 2, 3, 4}, 3600) fmt.Print(cache.Get(context.Background(), "wikipedia.org", dnsmessage.TypeA))
Output: [1 2 3 4]
type CacheBackend ¶
type MemoryBackend ¶
type MemoryBackend struct { CacheBackend // contains filtered or unexported fields }
MemoryBackend is an in-memory, freecache-based caching backend.
func (*MemoryBackend) Connect ¶
func (mb *MemoryBackend) Connect() error
func (*MemoryBackend) Get ¶
func (mb *MemoryBackend) Get(key string) []byte
func (*MemoryBackend) WithContext ¶
func (mb *MemoryBackend) WithContext(_ context.Context) CacheBackend
type RedisBackend ¶
type RedisBackend struct { CacheBackend // contains filtered or unexported fields }
RedisBackend is a Redis-based caching backend.
func (*RedisBackend) Connect ¶
func (rb *RedisBackend) Connect() error
func (*RedisBackend) Get ¶
func (rb *RedisBackend) Get(key string) []byte
func (*RedisBackend) WithContext ¶
func (rb *RedisBackend) WithContext(ctx context.Context) CacheBackend
Click to show internal directories.
Click to hide internal directories.