Skip to content

tico8/go-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-cache

Library for caching

Usage

package main

import "github.com/tico8/go-cache"

func main() {
  opt := cache.Option{
    ThresholdAccess: 0,
    ThresholdAccessCount: 0,
  }
  c := cache.New(opt)
  
  key := "testKey"
  value := "testValue"

  c.Set(key, value, time.Duration(10)) // expiration is 10 sec (default is 1 hour)
  resultValue, found := c.Get(key)
  c.Del(key)
}

Option

  • ThresholdSize
    Total size of cache
  • ThresholdAccess
    If it is accessed within N seconds, priority +1
  • ThresholdAccessCount
    If it is accessed more than N times, priority +1

Optimizing of cache

If the size of cache is greater than the ThresholdSize value, it is possible to optimize caching . Lower priority cache is deleted by optimizer.

package main

import "github.com/tico8/go-cache"

func main() {
  opt := cache.Option{
    ThresholdAccess: 1000000000, // 1 sec
    ThresholdAccessCount: 100, // 100 times
  }
  c := cache.New(opt)

  // Manually
  c.Optimize()

  // Executed in the 10 second intervals
  c.RunOptimizer(10)
	
  // Stop
  c.StopOptimizer()
}

About

Library for caching

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages