cache

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

cache.go

mmap_common.go

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFile   = fmt.Errorf("invalid cache file")
	ErrInvalidAccess = fmt.Errorf("invalid memory access")
	ErrChecksum      = fmt.Errorf("data checksum mismatch")
	ErrOutOfSpace    = fmt.Errorf("out of space")
)

Functions

func ToSlice added in v0.0.11

func ToSlice[E any](c *Cache) ([]E, error)

ToSlice 安全转换为类型切片

Types

type Cache added in v0.0.11

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

Cache 使用内存映射的跨进程安全缓存

func OpenCache added in v0.0.11

func OpenCache(name string, userSize int64) (*Cache, error)

OpenCache 创建或打开内存映射缓存

func (*Cache) Add added in v0.0.11

func (c *Cache) Add(delta int) error

func (*Cache) Close added in v0.0.11

func (c *Cache) Close() error

Close 安全关闭

func (*Cache) WriteData added in v0.0.11

func (c *Cache) WriteData(offset uint32, src []byte) error

WriteData 类型安全写入

type MemObject added in v0.0.11

type MemObject interface {
	Flush() error
	Unmap() error
	Bytes() []byte
}

MemObject 封装内存映射操作接口

type Pool

type Pool[E any] struct {
	// contains filtered or unexported fields
}

Pool 是一个泛型化的 sync.Pool 封装,用于缓存和复用对象。 对象在释放回池时会被重置为零值。

func (*Pool[E]) Acquire

func (p *Pool[E]) Acquire() *E

Acquire 从池中获取一个对象。如果池为空则创建新对象。 返回的对象会被重置为零值(通过 Release 时的重置保证)。

func (*Pool[E]) Release

func (p *Pool[E]) Release(obj *E)

Release 将对象放回池中。如果对象为 nil 则直接返回。 放回前会将对象重置为零值以保证下次获取时的状态。

Jump to

Keyboard shortcuts

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