cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CacheExpiration time.Duration = 12 * time.Hour // Max time that a request can exist in the cache
	MaxCacheMemory  int           = 500            // Max request can exist in the cache
)

Functions

func FindAndDel

func FindAndDel(arr []string, s string) []string

Find and delete string s in string slice

func HashCacheKey

func HashCacheKey(s string) string

Hash a string into SHA256

Types

type WikiCache

type WikiCache struct {
	Memory         map[string]models.RequestResult // Map store request result
	HashedKeyQueue []string                        // Key queue. Delete the first item if reach max cache
	CreatedTime    map[string]time.Time            // Map store created time
}

Cache to store Wikipedia request result

func MakeWikiCache

func MakeWikiCache() WikiCache

Create a cache that store:

- Key: API request URL

- Value: RequestResponse

func (*WikiCache) Add

func (cache *WikiCache) Add(s string, res models.RequestResult)

Add cache into the WikiCache

func (*WikiCache) Clear

func (cache *WikiCache) Clear()

Clear the whole Cache

func (*WikiCache) Get

func (cache *WikiCache) Get(s string) (models.RequestResult, error)

Get response from the Cache

func (WikiCache) GetLen

func (cache WikiCache) GetLen() int

Get WikiCache current number of cache

func (*WikiCache) Pop

func (cache *WikiCache) Pop()

Delete the first key in the Cache

Jump to

Keyboard shortcuts

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