cache

package
v1.1.46 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cache provides persistent file-based caching for tenant configuration.

The FileCache component enables the tenant Provider to degrade gracefully when ETCD is unavailable by maintaining a local copy of tenant data.

Features:

  • Atomic writes using temporary file + rename
  • JSON encoding for human-readable cache files
  • Configurable cache path via TENANT_CACHE_PATH env variable
  • Thread-safe operations with mutex protection

Usage:

cache := cache.NewFileCache()
data, err := cache.Load()
if err == nil {
    // Use cached data as fallback
}

cache.Save(tenantData) // Persist on ETCD updates

Package cache provides persistent cache layer for tenant data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec interface {
	Encode(data interface{}) ([]byte, error)
	Decode(bytes []byte, dest interface{}) error
}

Codec defines the encoding/decoding interface for cache data.

type FileCache

type FileCache struct {
	// contains filtered or unexported fields
}

FileCache provides persistent file-based caching for tenant data.

func NewFileCache

func NewFileCache() *FileCache

NewFileCache creates a new file-based cache. The cache path can be configured via TENANT_CACHE_PATH env variable. Default path: ./cache/tenant_metadata.json

func NewFileCacheWithPath

func NewFileCacheWithPath(path string) *FileCache

NewFileCacheWithPath creates a cache with a specific file path.

func (*FileCache) Clear

func (f *FileCache) Clear() error

Clear removes the cache file.

func (*FileCache) IsAvailable

func (f *FileCache) IsAvailable() bool

IsAvailable checks if the cache file exists and is readable.

func (*FileCache) Load

func (f *FileCache) Load() (*tenantSnapshot, error)

Load reads cached tenant data from file. Returns os.ErrNotExist if cache file doesn't exist.

func (*FileCache) Save

func (f *FileCache) Save(data *tenantSnapshot) error

Save writes tenant data to cache file atomically. Uses temporary file + rename to ensure consistency.

type JSONCodec

type JSONCodec struct{}

JSONCodec implements Codec using JSON encoding.

func (JSONCodec) Decode

func (JSONCodec) Decode(bytes []byte, dest interface{}) error

func (JSONCodec) Encode

func (JSONCodec) Encode(data interface{}) ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL