caches

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashPrefixDirPrefixLen is length heads hash prefix
	// get the first 4 character of hash string, then save
	// the content to rootDir/hash{0:4}/hash
	HashPrefixDirPrefixLen = 4
)

Variables

This section is empty.

Functions

func GenerateCacheFromConfig

func GenerateCacheFromConfig(cacheCfg *config.CacheConfig) interfaces.Cache

func NewComposedCache

func NewComposedCache(inner, outer interfaces.Cache, mode CacheMode) interfaces.Cache

func NewDiskCache

func NewDiskCache(cfg *config.Cache) interfaces.Cache

func NewMemoryCache

func NewMemoryCache(cfg *config.Cache) interfaces.Cache

func NewRedisCache

func NewRedisCache(cfg *config.Cache) interfaces.Cache

Types

type CacheMode

type CacheMode uint32
const (
	// ModeReadThrough means that if we Get a key from ComposedCache and not found in outer(faster) one,
	// then we will get from inner(slower) one, and set the result into outer.
	ModeReadThrough CacheMode = 1 << (iota + 1)

	// ModeWriteThrough means that if we 'Set' a key into ComposedCache, it will be not only 'Set' into inner(slower) one,
	// and also be 'Set' into outer(faster) one.
	ModeWriteThrough
)

type ComposedCache

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

ComposedCache hold two caches and take the outer one as a faster one take inner one as slower one.

  • When invoking Get, first get from outer(faster) one, if not found in outer(faster) one, then it will find in inner(slower) one.
  • If it found in outer(faster) one && ModeReadThrough was set, the result from outer(faster) one will be Set into inner(slower) one.
  • If we set a pair of key and value, this key will be set into inner(slower) one first, and then if ModeWriteThrough was set, this key will be set in outer(faster) one.

func (*ComposedCache) Check

func (c *ComposedCache) Check(ctx context.Context) error

func (*ComposedCache) Contains

func (c *ComposedCache) Contains(ctx context.Context, d *repb.Digest) (bool, error)

func (*ComposedCache) Delete

func (c *ComposedCache) Delete(ctx context.Context, d *repb.Digest) error

func (*ComposedCache) FindMissing

func (c *ComposedCache) FindMissing(ctx context.Context, digests []*repb.Digest) ([]*repb.Digest, error)

func (*ComposedCache) Get

func (c *ComposedCache) Get(ctx context.Context, d *repb.Digest) ([]byte, error)

func (*ComposedCache) GetMulti

func (c *ComposedCache) GetMulti(ctx context.Context, digests []*repb.Digest) (map[*repb.Digest][]byte, error)

func (*ComposedCache) Reader

func (c *ComposedCache) Reader(ctx context.Context, d *repb.Digest, offset int64) (io.ReadCloser, error)

func (*ComposedCache) Set

func (c *ComposedCache) Set(ctx context.Context, d *repb.Digest, data []byte) error

func (*ComposedCache) SetMulti

func (c *ComposedCache) SetMulti(ctx context.Context, kvs map[*repb.Digest][]byte) error

func (*ComposedCache) Size

func (c *ComposedCache) Size() int64

Size get the inner size + outer size

func (*ComposedCache) WithIsolation

func (c *ComposedCache) WithIsolation(ctx context.Context, cacheType interfaces.CacheType, remoteInstanceName string) (interfaces.Cache, error)

func (*ComposedCache) Writer

func (c *ComposedCache) Writer(ctx context.Context, d *repb.Digest) (io.WriteCloser, error)

type DiskCache

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

DiskCache implements the disk-based interfaces.Cache

func (*DiskCache) Check

func (c *DiskCache) Check(ctx context.Context) error

func (*DiskCache) Contains

func (c *DiskCache) Contains(ctx context.Context, d *repb.Digest) (bool, error)

Contains only call lru

func (*DiskCache) Delete

func (c *DiskCache) Delete(ctx context.Context, d *repb.Digest) error

func (*DiskCache) FindMissing

func (c *DiskCache) FindMissing(ctx context.Context, digests []*repb.Digest) ([]*repb.Digest, error)

func (*DiskCache) Get

func (c *DiskCache) Get(ctx context.Context, d *repb.Digest) ([]byte, error)

func (*DiskCache) GetMulti

func (c *DiskCache) GetMulti(ctx context.Context, digests []*repb.Digest) (map[*repb.Digest][]byte, error)

func (*DiskCache) Reader

func (c *DiskCache) Reader(ctx context.Context, d *repb.Digest, offset int64) (io.ReadCloser, error)

func (*DiskCache) Set

func (c *DiskCache) Set(ctx context.Context, d *repb.Digest, data []byte) error

func (*DiskCache) SetMulti

func (c *DiskCache) SetMulti(ctx context.Context, kvs map[*repb.Digest][]byte) error

func (*DiskCache) Size

func (c *DiskCache) Size() int64

func (*DiskCache) WithIsolation

func (c *DiskCache) WithIsolation(ctx context.Context, cacheType interfaces.CacheType, remoteInstanceName string) (interfaces.Cache, error)

func (*DiskCache) Writer

func (c *DiskCache) Writer(ctx context.Context, d *repb.Digest) (io.WriteCloser, error)

type MapEntry

type MapEntry struct {
	Key  string
	Size int64
}

type MemoryCache

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

func (*MemoryCache) Check

func (m *MemoryCache) Check(ctx context.Context) error

func (*MemoryCache) Contains

func (m *MemoryCache) Contains(ctx context.Context, d *repb.Digest) (bool, error)

func (*MemoryCache) Delete

func (m *MemoryCache) Delete(ctx context.Context, d *repb.Digest) error

func (*MemoryCache) FindMissing

func (m *MemoryCache) FindMissing(ctx context.Context, digests []*repb.Digest) ([]*repb.Digest, error)

func (*MemoryCache) Get

func (m *MemoryCache) Get(ctx context.Context, d *repb.Digest) ([]byte, error)

func (*MemoryCache) GetMulti

func (m *MemoryCache) GetMulti(ctx context.Context, digests []*repb.Digest) (map[*repb.Digest][]byte, error)

func (*MemoryCache) Reader

func (m *MemoryCache) Reader(ctx context.Context, d *repb.Digest, offset int64) (io.ReadCloser, error)

func (*MemoryCache) Set

func (m *MemoryCache) Set(ctx context.Context, d *repb.Digest, data []byte) error

func (*MemoryCache) SetMulti

func (m *MemoryCache) SetMulti(ctx context.Context, kvs map[*repb.Digest][]byte) error

func (*MemoryCache) Size

func (m *MemoryCache) Size() int64

func (*MemoryCache) WithIsolation

func (m *MemoryCache) WithIsolation(ctx context.Context, cacheType interfaces.CacheType, remoteInstanceName string) (interfaces.Cache, error)

func (*MemoryCache) Writer

func (m *MemoryCache) Writer(ctx context.Context, d *repb.Digest) (io.WriteCloser, error)

type Metrics

type Metrics struct {
	sync.RWMutex

	Total int64
	// contains filtered or unexported fields
}

func (*Metrics) GetHit

func (m *Metrics) GetHit() int64

func (*Metrics) GetHitRate

func (m *Metrics) GetHitRate() float64

func (*Metrics) GetMiss

func (m *Metrics) GetMiss() int64

func (*Metrics) GetTotal

func (m *Metrics) GetTotal() int64

func (*Metrics) Hit

func (m *Metrics) Hit()

func (*Metrics) Miss

func (m *Metrics) Miss()

type MultiCloser

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

func (*MultiCloser) Close

func (m *MultiCloser) Close() error

type ReadCloser

type ReadCloser struct {
	io.Reader
	io.Closer
}

type RedisCache

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

func (*RedisCache) Check

func (r *RedisCache) Check(ctx context.Context) error

func (*RedisCache) Contains

func (r *RedisCache) Contains(ctx context.Context, d *repb.Digest) (bool, error)

func (*RedisCache) Delete

func (r *RedisCache) Delete(ctx context.Context, d *repb.Digest) error

func (*RedisCache) FindMissing

func (r *RedisCache) FindMissing(ctx context.Context, digests []*repb.Digest) ([]*repb.Digest, error)

func (*RedisCache) Get

func (r *RedisCache) Get(ctx context.Context, d *repb.Digest) ([]byte, error)

func (*RedisCache) GetMulti

func (r *RedisCache) GetMulti(ctx context.Context, digests []*repb.Digest) (map[*repb.Digest][]byte, error)

func (*RedisCache) Reader

func (r *RedisCache) Reader(ctx context.Context, d *repb.Digest, offset int64) (io.ReadCloser, error)

func (*RedisCache) Set

func (r *RedisCache) Set(ctx context.Context, d *repb.Digest, data []byte) error

func (*RedisCache) SetMulti

func (r *RedisCache) SetMulti(ctx context.Context, kvs map[*repb.Digest][]byte) error

func (*RedisCache) Size

func (r *RedisCache) Size() int64

func (*RedisCache) WithIsolation

func (r *RedisCache) WithIsolation(ctx context.Context, cacheType interfaces.CacheType, remoteInstanceName string) (interfaces.Cache, error)

func (*RedisCache) Writer

func (r *RedisCache) Writer(ctx context.Context, d *repb.Digest) (io.WriteCloser, error)

Jump to

Keyboard shortcuts

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