Documentation ¶
Overview ¶
Package filecache is a tool to write data from any io.Reader to cache files with TTL and metadata.
Index ¶
- Constants
- Variables
- type FileCache
- func (fc *FileCache) Create(meta *Meta) (item *Item, err error)
- func (fc *FileCache) Invalidate(key string, namespace string) error
- func (fc *FileCache) Path() string
- func (fc *FileCache) Read(key string, namespace string) (item *Item, err error)
- func (fc *FileCache) Write(meta *Meta, src io.Reader) (written int64, err error)
- func (fc *FileCache) WriteOpen(meta *Meta, src io.Reader) (item *Item, written int64, err error)
- type Item
- type Meta
- type Scanner
- type ScannerHitFunc
Constants ¶
View Source
const MetaPostfix = "--meta"
MetaPostfix is a metadata files name postfix
Variables ¶
View Source
var ( // NamespaceDefault is a default cache files namespace NamespaceDefault = "dft" // ExtDefault is a default files extension string ExtDefault = ".cache" // TTLDefault is a default value // in seconds of cache items' Time-To-Live TTLDefault = int64(-1) // GCDivisor is a garbage collector run probability divisor // (e.g. 100 is 1/100 probability) GCDivisor uint = 100 )
Functions ¶
This section is empty.
Types ¶
type FileCache ¶
type FileCache struct { // NamespaceDefault is a default namespace if left empty in functions params NamespaceDefault string // Ext is a cache files extension string Ext string // TTLDefault is a default TTL of cache instance items TTLDefault int64 // contains filtered or unexported fields }
FileCache is a file-based cache structure
func (*FileCache) Create ¶ added in v1.2.0
Create cache file by metadata and open it. Returns cache Item and error if occurs.
func (*FileCache) Invalidate ¶ added in v1.0.0
Invalidate deletes cache item by its key & namespace
type Meta ¶ added in v1.0.0
type Meta struct { // Key is a non-hashed unique for namespace item id // Required Key string `json:"k"` // Namespace is a cache item category folder name // If empty FileCache.NamespaceDefault will be set Namespace string `json:"n"` // OriginalName is an original file name; optional OriginalName string `json:"o,omitempty"` // TTL is a item's time-to-live value in seconds TTL int64 `json:"t"` // Created is a time when cache file was written // Do not set it by yourself Created int64 `json:"c"` // Fields is a map of any others metadata fields Fields map[string]interface{} `json:"f,omitempty"` }
Meta is a cache item metadata structure Short json keys are used to reduce file size
func MetaFromFile ¶ added in v1.3.0
MetaFromFile reads cache metadata from file
func (*Meta) IsExpired ¶ added in v1.3.0
IsExpired returns true if file is expired or if its TTL is 0
func (*Meta) SaveToFile ¶ added in v1.3.0
SaveToFile saves JSON-encoded metadata to file
type Scanner ¶ added in v1.3.0
type Scanner struct {
// contains filtered or unexported fields
}
Scanner is a tool to walk through existing cache files
func NewScanner ¶ added in v1.3.0
NewScanner creates new Scanner instance
Click to show internal directories.
Click to hide internal directories.