lfu

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: MIT Imports: 2 Imported by: 0

README

LFU Redis cache library for Golang

LFU Redis implements LFU Cache algorithm using Redis as data storage

LFU Redis Package gives you control over Cache Capacity in case you're using multipurpose Redis instance and avoid using eviction policy

Installation

go get -u github.com/m7shapan/lfu-redis

Quickstart

package lfu_test

import (
	"fmt"

	"github.com/go-redis/redis/v8"
	"github.com/m7shapan/lfu-redis"
)

func ExampleUsage() {
	redisClient := redis.NewClient(&redis.Options{})

	cache := lfu.New(10000, redisClient)

	err := cache.Put("key", "value")
	if err != nil {
		panic(err)
	}

	value, err := cache.Get("key")
	if err != nil {
		panic(err)
	}

	fmt.Println(value)
	// Output: value
}

Documentation

Index

Constants

View Source
const LFUHashName = "LFUCacheHash"
View Source
const LFUSortedSetName = "LFUCacheSortedSet"

Variables

This section is empty.

Functions

This section is empty.

Types

type LFUCache

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

func New

func New(capacity int64, redisClient *redis.Client) *LFUCache

func (*LFUCache) DelItem

func (c *LFUCache) DelItem(key string) (err error)

DelItem remove item from cache

func (*LFUCache) Flush

func (c *LFUCache) Flush() (err error)

Flush remove all cache

func (*LFUCache) Get

func (c *LFUCache) Get(key string) (value string, err error)

Get return item from cache

func (*LFUCache) Put

func (c *LFUCache) Put(key string, value interface{}) (err error)

Put caches item

Jump to

Keyboard shortcuts

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