Skip to content

Latest commit

 

History

History
32 lines (27 loc) · 781 Bytes

README.md

File metadata and controls

32 lines (27 loc) · 781 Bytes

Fcache

File cache with LRU algorithm, contains memory cache and disk cache.

Example

package main

import (
	"fmt"

	"github.com/nuczzz/fcache"
)

func main() {
	memCache := fcache.NewMemCache(10, false)
	memCache.Set("key1", []byte("123456789"))
	memCache.Set("key2", []byte("0"))
	memCache.Set("key3", []byte("1"))
	fmt.Println(memCache.Get("key3"))
	fmt.Println(memCache.Get("key1"))
	hit, total := memCache.GetHitInfo()
	fmt.Printf("hit: %v, total: %v\n", hit, total)

	diskCache := fcache.NewDiskCache(10, false, "./cache")
	diskCache.Set("key1", []byte("123456789"))
	diskCache.Set("key2", []byte("0"))
	diskCache.Set("key3", []byte("1"))
	fmt.Println(diskCache.Get("key3"))
	hit, total = diskCache.GetHitInfo()
	fmt.Printf("hit: %v, total: %v\n", hit, total)
}