cache

package
v0.0.11-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Copyright (c) Microsoft Corporation. Licensed under the MIT License.

Copyright (c) Microsoft Corporation. Licensed under the MIT License.

Copyright (c) Microsoft Corporation. Licensed under the MIT License.

Copyright (c) Microsoft Corporation. Licensed under the MIT License.

Index

Constants

This section is empty.

Variables

View Source
var (
	// FilesCacheMaxCost is the capacity of the files cache.
	FilesCacheMaxCost int64 = 4 * 1024 * 1024 * 1024 // 4 Gib

	// MemoryCacheMaxCost is the capacity of the memory cache.
	MemoryCacheMaxCost int64 = 1 * 1024 * 1024 * 1024 // 1 Gib

	// Path is the path to the cache directory.
	Path string = "/tmp/distribution/peerd/cache"
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Size gets the size of the file.
	Size(path string) (int64, bool)

	// PutSize sets size of the file.
	PutSize(path string, length int64) bool

	// Exists checks if the given chunk of the file is already cached.
	Exists(name string, offset int64) bool

	// GetOrCreate gets the cached value if available, otherwise downloads the file.
	GetOrCreate(name string, offset int64, count int, fetch func() ([]byte, error)) ([]byte, error)
}

Cache describes a cache of files.

func New

func New(ctx context.Context, cacheBlockSize int64) Cache

New creates a new cache of files. cacheBlockSize is the fixed size of the cache block in bytes, and is used to evaluate the cost of each item in the cache.

type SyncMap

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

SyncMap is a map that can be safely accessed concurrently.

func NewSyncMap

func NewSyncMap(maxEntries int) *SyncMap

NewSyncMap creates a new SyncMap with the specified maximum number of entries. If the maximum number of entries is less than or equal to 0, it will be set to 1.

func (*SyncMap) Delete

func (sm *SyncMap) Delete(key string)

Delete removes the entry with the specified key from the SyncMap. If the key does not exist, this method does nothing.

func (*SyncMap) Get

func (sm *SyncMap) Get(key string) (entry interface{}, ok bool)

Get retrieves the value associated with the given key from the SyncMap. It returns the value and a boolean indicating whether the key was found.

func (*SyncMap) Set

func (sm *SyncMap) Set(key string, entry interface{})

Set sets a new entry or updates an existing one. Set adds or updates an entry in the SyncMap with the specified key. If the key already exists in the map, the entry will be updated. If the key does not exist and the map is at capacity, some entries will be evicted first.

Jump to

Keyboard shortcuts

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