Skip to content

joaovictorsl/fooche

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fooche

A naive caching library created to be used on dcache.

Install

  go get github.com/joaovictorsl/fooche

Usage

package example

import (
	"fmt"
	"time"

	"github.com/joaovictorsl/fooche"
	"github.com/joaovictorsl/fooche/evict"
)

func main() {
	// Time in which expired data will be cleaned from cache
	cleanInterval := 10 * time.Second
	// Maps a data size (bytes) to its capacity
	// If 10 is mapped to 4 it means we'll be able to store 4 keys
    // with data size of 10 bytes or less
	sizeToCapMap := map[int]int{
		10: 4,
	}
	// Function to create an eviction policy based on storage capacity
	createLruPolicy := func(capacity int) evict.EvictionPolicy[string] {
		return evict.NewLRU[string](capacity)
	}
	// Creating caches
	// Only bounded caches use eviction policies
	c1 := fooche.NewCleanIntervalBounded(cleanInterval, sizeToCapMap, createLruPolicy)
	// c2 := fooche.NewCleanInterval(cleanInterval)
	// c3 := fooche.NewSimpleBounded(sizeToCapMap, createLruPolicy)
	// c4 := fooche.NewSimple()

	c1.Delete("key")
	c1.Get("key")
	c1.Has("key")
	c1.Set("key", []byte("data"), time.Second*30)
	fmt.Println(c1.String())
}

About

A simple caching library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages