storage

package
v2.13.12 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONDiskStorage

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

JSONDiskStorage is a Storage implementation that uses the file system as persistence backend, storing the objects as JSON. This requires that any object that has to be stored is Marshallable and Unmarshallable.

func NewJSONDiskStorage

func NewJSONDiskStorage(rootPath string) JSONDiskStorage

NewJSONDiskStorage returns a JSONDiskStorage using the rootPath argument as root folder for the persistent entities.

func (JSONDiskStorage) Delete

func (j JSONDiskStorage) Delete(key string) error

Delete removes the cached data for the given key. If the data does not exist, the system does not return any error.

func (JSONDiskStorage) Read

func (j JSONDiskStorage) Read(key string, valuePtr interface{}) (int64, error)

Read gets the value associated to a given key and stores it in the value referenced by the pointer passed as second argument This implementation adds a restriction to the key name: it must be a valid file name (without extension).

func (JSONDiskStorage) Write

func (j JSONDiskStorage) Write(key string, value interface{}) error

Write stores a value for a given key. Implementors must save also the time when it was stored. This implementation adds a restriction to the key name: it must be a valid file name (without extension).

type MemoryStorage added in v2.7.1

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

MemoryStorage stores data in memory.

func (*MemoryStorage) Delete added in v2.7.1

func (m *MemoryStorage) Delete(key string) error

func (*MemoryStorage) Read added in v2.7.1

func (m *MemoryStorage) Read(key string, returnValue interface{}) (int64, error)

func (*MemoryStorage) Write added in v2.7.1

func (m *MemoryStorage) Write(key string, value interface{}) error

type Storage

type Storage interface {
	// Write stores a value for a given key. Implementors must save also the time when it was stored.
	// The value can be any type.
	Write(key string, value interface{}) error
	// Read gets the value associated to a given key and stores in the value referenced by the pointer passed as argument.
	// It returns the Unix timestamp when the value was stored (in seconds), or an error if the Read operation failed.
	// It may return any type of value.
	Read(key string, valuePtr interface{}) (int64, error)
	// Delete removes the cached data for the given key. If the data does not exist, the system does not return
	// any error.
	Delete(key string) error
}

Storage defines the interface of a Key-Value storage system, which is able to store the timestamp where the key was stored.

Jump to

Keyboard shortcuts

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