carrot

package module
v0.0.0-...-a1f9782 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 7 Imported by: 0

README

carrot

GitHub Go Report Card build-test

Features

Memory Cache

Implements an in-memory cache key:value (similar to C# MemoryCache)

Usage

Quick Start

1.Install

  go get github.com/jiansoft/carrot

2.Use examples

import (
    "time"
    
    "github.com/jiansoft/carrot"
)

func main() {
    
    //Keep an item in memory 
    carrot.Default.Delay("qq", "Qoo", time.Second)
    //Read returns the value if the key exists in the cache and it's not expired.
    val, ok := carrot.Default.Read("qq")
    //Have eturns true if the memory has the item and it's not expired.
    yes := carrot.Default.Have("qq")
    //Removes an item from the memory
    carrot.Default.Forget("qq")

More example

License

Copyright (c) 2023

Released under the MIT license:

Documentation

Index

Constants

View Source
const (
	KindSliding cacheKind = iota
	KindNormal
)

Variables

View Source
var (
	Default = memoryCache()
)

Functions

This section is empty.

Types

type CacheCoherent

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

CacheCoherent Wrapper for the memory cache entries collection.

func New

func New() *CacheCoherent

func (*CacheCoherent) Delay

func (cc *CacheCoherent) Delay(key, val any, ttl time.Duration)

Delay expires after a period of time. e.g. time.Hour, it will expire after one hour from now

func (*CacheCoherent) Forever

func (cc *CacheCoherent) Forever(key, val any)

Forever never expiration

func (*CacheCoherent) Forget

func (cc *CacheCoherent) Forget(key any)

Forget removes an item from the memory

func (*CacheCoherent) Have

func (cc *CacheCoherent) Have(key any) bool

Have returns true if the memory has the item, and it's not expired.

func (*CacheCoherent) Inactive

func (cc *CacheCoherent) Inactive(key, val any, inactive time.Duration)

Inactive expires after it is inactive for more than a period of time

func (*CacheCoherent) Read

func (cc *CacheCoherent) Read(key any) (any, bool)

Read returns the value if the key exists in the cache

func (*CacheCoherent) Reset

func (cc *CacheCoherent) Reset()

Reset removes all items from the memory

func (*CacheCoherent) SetScanFrequency

func (cc *CacheCoherent) SetScanFrequency(frequency time.Duration) bool

SetScanFrequency sets a new frequency value

func (*CacheCoherent) Statistics

func (cc *CacheCoherent) Statistics() CacheStatistics

func (*CacheCoherent) Until

func (cc *CacheCoherent) Until(key, val any, until time.Time)

Until expires at a certain time. e.g. 2023-01-01 12:31:59.999

type CachePriority

type CachePriority int
const (
	PriorityLow CachePriority = iota
	PriorityNormal
	PriorityHigh
	PriorityNeverRemove
)

type CacheStatistics

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

type ConcurrentPriorityQueue

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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