cache

package
v1.21.9 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package mmap allows mapping files into memory. It tries to provide a simple, reasonably portable interface, but doesn't go out of its way to abstract away every little platform detail. This specifically means:

  • forked processes may or may not inherit mappings
  • a file's timestamp may or may not be updated by writes through mappings
  • specifying a size larger than the file's actual size can increase the file's size
  • If the mapped file is being modified by another process while your program's running, don't expect consistent results between platforms

Index

Constants

View Source
const (
	// RDONLY maps the memory read-only.
	// Attempts to write to the MemObject object will result in undefined behavior.
	RDONLY = 0
	// RDWR maps the memory as read-write. Writes to the MemObject object will update the
	// underlying file.
	RDWR = 1 << iota
	// COPY maps the memory as copy-on-write. Writes to the MemObject object will affect
	// memory, but the underlying file will remain unchanged.
	COPY
	// If EXEC is set, the mapped memory is marked as executable.
	EXEC
)
View Source
const (
	// If the ANON flag is set, the mapped memory will not be backed by a file.
	ANON = 1 << iota
)

Variables

This section is empty.

Functions

func ToSlices added in v1.19.7

func ToSlices[E any](cache *Cache) []E

ToSlices 内存转切片

Types

type Cache added in v1.21.4

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

Cache 使用跨平台的mmap构建的快速缓存

func OpenCache

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

OpenCache 打开本地缓存

func (*Cache) Close added in v1.21.4

func (c *Cache) Close()

Close 关闭缓存

func (*Cache) Flush added in v1.21.4

func (c *Cache) Flush() error

Flush 同步数据到磁盘

type Map added in v1.18.5

type Map[K any, V any] struct {
	// contains filtered or unexported fields
}

Map 二次封装的泛型sync.Map

func (*Map[K, V]) Get added in v1.18.5

func (this *Map[K, V]) Get(k K) (V, bool)

func (*Map[K, V]) Put added in v1.18.5

func (this *Map[K, V]) Put(k K, v V)

type MemObject added in v1.21.4

type MemObject []byte

MemObject represents a file mapped into memory.

func FileMap added in v1.19.7

func FileMap(f *os.File, prot, flags int) (MemObject, error)

FileMap maps an entire file into memory. If ANON is set in flags, f is ignored.

func MapRegion added in v1.19.7

func MapRegion(f *os.File, length int, prot, flags int, offset int64) (MemObject, error)

MapRegion maps part of a file into memory. The offset parameter must be a multiple of the system's page size. If length < 0, the entire file will be mapped. If ANON is set in flags, f is ignored.

func (MemObject) Flush added in v1.21.4

func (m MemObject) Flush() error

Flush synchronizes the mapping's contents to the file's contents on disk.

func (MemObject) Lock added in v1.21.4

func (m MemObject) Lock() error

Lock keeps the mapped region in physical memory, ensuring that it will not be swapped out.

func (MemObject) Unlock added in v1.21.4

func (m MemObject) Unlock() error

Unlock reverses the effect of Lock, allowing the mapped region to potentially be swapped out. If m is already unlocked, aan error will result.

func (*MemObject) Unmap added in v1.21.4

func (m *MemObject) Unmap() error

Unmap deletes the memory mapped region, flushes any remaining changes, and sets m to nil. Trying to read or write any remaining references to m after Unmap is called will result in undefined behavior. Unmap should only be called on the slice value that was originally returned from a call to FileMap. Calling Unmap on a derived slice may cause errors.

type Pool added in v1.18.5

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

Pool 二次封装的泛型sync.Pool

func (*Pool[E]) Acquire added in v1.18.5

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

Acquire 申请内存

func (*Pool[E]) Release added in v1.18.5

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

Release 释放内存

Jump to

Keyboard shortcuts

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