cache

package
v13.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Overview

Package cache provides methods and structs for caching data

Index

Constants

View Source
const (
	MILLISECOND = time.Millisecond // 1 ms
	SECOND      = time.Second      // 1 sec
	MINUTE      = time.Minute      // 1 min
	HOUR        = time.Hour        // 1 hr
	DAY         = 24 * HOUR        // 24 hr
	WEEK        = 7 * DAY          // 7 d
	MONTH       = 30 * DAY         // 30 d
	YEAR        = 365 * DAY        // 365 d
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Has returns true if cache contains data for given key
	Has(key string) bool

	// Size returns number of items in cache
	Size() int

	// Expired returns number of expired items in cache
	Expired() int

	// Set adds or updates item in cache
	Set(key string, data any, expiration ...time.Duration) bool

	// GetWithExpiration returns item from cache
	Get(key string) any

	// GetWithExpiration returns item expiration date
	GetExpiration(key string) time.Time

	// GetWithExpiration returns item from cache and expiration date or nil
	GetWithExpiration(key string) (any, time.Time)

	// Delete removes item from cache
	Delete(key string) bool

	// Flush removes all data from cache
	Flush() bool
}

Cache is cache backend interface

type Duration added in v13.3.1

type Duration = time.Duration

Duration is time.Duration alias

Directories

Path Synopsis
Package fs provides cache with file system storage
Package fs provides cache with file system storage
Package memory provides cache with in-memory storage
Package memory provides cache with in-memory storage

Jump to

Keyboard shortcuts

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