Skip to content

Golang caching in memory for all data types / files

Notifications You must be signed in to change notification settings

Suremeo/cachemanager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

How to install

Run go get github.com/suremeo/cachemanager

Examples

package main

import (
	"github.com/suremeo/cachemanager"
    "time"
)

var cache = cachemanager.NewCache().Run()

func main() {
	// Add an item, item can be anything, a structure, bytes, string, int, etc

	cache.Set("Suremeo", "cool guy")

	// Set how long items stay in cache (seconds) before they get automatically removed (preset is 30)

	cache.Expire = 60 * time.Second
    
    // Set how often to tick (Loops through all cached items and removes expired ones)
    
    cache.Tick = 1 * time.Second

	// fetch from cache

	item, _ := cache.Get("Suremeo")
	println(item.Data.(string))

	// Manually remove something from cache (usually it does it automatically after it expires)

	cache.Remove("Suremeo")

	// Cache file reading (if the file isn't already in the cache it read the file and adds it)

	cache.File("Booger.png")
	
	// Clear entire cache
	
	cache.Clear()
}

About

Golang caching in memory for all data types / files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages