filecache

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 7 Imported by: 0

README

filecache

Very simple file cache for Go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Ext = ".cache"

Functions

func DeleteIf

func DeleteIf[T any](c *Cacher, bucketName string, cond func(key string, value T) bool) error

func GetAll

func GetAll[T any](c *Cacher, bucketName string) (map[string]T, error)

func Range

func Range[T any](c *Cacher, bucketName string, f func(key string, value T) bool) error

func ToPtr

func ToPtr[T any](v T) *T

Types

type Bucket

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

Bucket represents a cache bucket with a name and TTL.

func NewBucket

func NewBucket(name string, ttl time.Duration) Bucket

func (*Bucket) Name

func (b *Bucket) Name() string

func (*Bucket) TTL

func (b *Bucket) TTL() time.Duration

type CacheStore

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

CacheStore represents a single-process, file-based, key/value cache store.

type Cacher

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

func NewCacher

func NewCacher(dir string) (*Cacher, error)

func NewCacherWithExt added in v0.1.1

func NewCacherWithExt(dir, ext string) (*Cacher, error)

func (*Cacher) CleanBucket

func (c *Cacher) CleanBucket(bucketName string) error

func (*Cacher) Close

func (c *Cacher) Close() error

Close closes all the cache stores.

func (*Cacher) Delete

func (c *Cacher) Delete(bucketName string, key string) error

Delete deletes the value for the given key from the given bucket.

func (*Cacher) EmptyBucket

func (c *Cacher) EmptyBucket(bucketName string) error

EmptyBucket empties the given bucket (removes all items).

func (*Cacher) Get

func (c *Cacher) Get(bucketName string, key string, out interface{}) (bool, error)

Get retrieves the value for the given key from the given bucket. If the key does not exist or has expired, it returns false. This removes the item from the cache if it has expired.

func (*Cacher) GetFrozen

func (c *Cacher) GetFrozen(bucketName string, key string, out interface{}) (bool, error)

GetFrozen retrieves the value for the given key from the given bucket without checking for expiration.

func (*Cacher) GetTotalSize

func (c *Cacher) GetTotalSize() (int64, error)

GetTotalSize returns the total size of all files in the cache directory that match the given filter. The size is in bytes.

func (*Cacher) RemoveAllBy

func (c *Cacher) RemoveAllBy(filter func(filename string) bool) error

RemoveAllBy removes all files in the cache directory that match the given filter.

func (*Cacher) RemoveBucket

func (c *Cacher) RemoveBucket(bucketName string) error

RemoveBucket removes the given bucket.

func (*Cacher) Set

func (c *Cacher) Set(bucketName string, ttl time.Duration, key string, value interface{}) error

Set sets the value for the given key in the given bucket.

func (*Cacher) SetFrozen

func (c *Cacher) SetFrozen(bucketName string, key string, value interface{}) error

SetFrozen sets the item with no expiration in the given bucket.

Jump to

Keyboard shortcuts

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