All Projects → muesli → Cache2go

muesli / Cache2go

Licence: other
Concurrency-safe Go caching library with expiration capabilities and access counters

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Cache2go

Lemmur
🐒 A mobile client for lemmy
Stars: ✭ 114 (-93.11%)
Mutual labels:  hacktoberfest
React Most Wanted
React starter kit with "Most Wanted" application features
Stars: ✭ 1,867 (+12.88%)
Mutual labels:  hacktoberfest
Cchoco
Community resource to manage Chocolatey
Stars: ✭ 115 (-93.05%)
Mutual labels:  hacktoberfest
Madelineproto
Async PHP client/server API for the telegram MTProto protocol
Stars: ✭ 1,776 (+7.38%)
Mutual labels:  hacktoberfest
Graphql Schema
GitHub’s GraphQL Schema with validation. Automatically updated.
Stars: ✭ 113 (-93.17%)
Mutual labels:  hacktoberfest
Developer Community Stats
🚀 A repository to encourage beginners to contribute to open source and for all contributors to view their Github stats
Stars: ✭ 116 (-92.99%)
Mutual labels:  hacktoberfest
Competitive Programming
Hello Programmers 💻 , A one-stop Destination✏️✏️ for all your Competitive Programming Resources.📗📕 Refer CONTRIBUTING.md for contributions
Stars: ✭ 113 (-93.17%)
Mutual labels:  hacktoberfest
Tinysearch
🔍 Tiny, full-text search engine for static websites built with Rust and Wasm
Stars: ✭ 1,705 (+3.08%)
Mutual labels:  hacktoberfest
Vscode Matlab
MATLAB support for Visual Studio Code
Stars: ✭ 114 (-93.11%)
Mutual labels:  hacktoberfest
Pssharedgoods
PSSharedGoods is little PowerShell Module that primary purpose is to be useful for multiple tasks, unrelated to each other. I've created this module as “a glue” between my other modules.
Stars: ✭ 115 (-93.05%)
Mutual labels:  hacktoberfest
Gitreflow
Reflow automatically creates pull requests, ensures the code review is approved, and squash merges finished branches to master with a great commit message template.
Stars: ✭ 1,488 (-10.04%)
Mutual labels:  hacktoberfest
Scriptsdump
The biggest dump of scripts ever!
Stars: ✭ 114 (-93.11%)
Mutual labels:  hacktoberfest
Implicit Hie
Auto generate a stack or cabal multi component hie.yaml file
Stars: ✭ 114 (-93.11%)
Mutual labels:  hacktoberfest
U Root
A fully Go userland with Linux bootloaders! u-root can create a one-binary root file system (initramfs) containing a busybox-like set of tools written in Go.
Stars: ✭ 1,816 (+9.79%)
Mutual labels:  hacktoberfest
Influxer
InfluxDB ActiveRecord-style
Stars: ✭ 115 (-93.05%)
Mutual labels:  hacktoberfest
Graphql Live Query
Realtime GraphQL Live Queries with JavaScript
Stars: ✭ 112 (-93.23%)
Mutual labels:  hacktoberfest
Goodwork
Self hosted project management and collaboration tool powered by TALL stack
Stars: ✭ 1,730 (+4.59%)
Mutual labels:  hacktoberfest
Spec
The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.
Stars: ✭ 1,860 (+12.45%)
Mutual labels:  hacktoberfest
Meteor Timesync
NTP-style time synchronization between server and client, and facilities to use server time reactively in Meteor applications.
Stars: ✭ 115 (-93.05%)
Mutual labels:  hacktoberfest
Gramjs
NodeJS MTProto API Telegram client library,
Stars: ✭ 113 (-93.17%)
Mutual labels:  hacktoberfest

cache2go

Latest Release Build Status Coverage Status Go ReportCard GoDoc

Concurrency-safe golang caching library with expiration capabilities.

Installation

Make sure you have a working Go environment (Go 1.2 or higher is required). See the install instructions.

To install cache2go, simply run:

go get github.com/muesli/cache2go

To compile it from source:

cd $GOPATH/src/github.com/muesli/cache2go
go get -u -v
go build && go test -v

Example

package main

import (
	"github.com/muesli/cache2go"
	"fmt"
	"time"
)

// Keys & values in cache2go can be of arbitrary types, e.g. a struct.
type myStruct struct {
	text     string
	moreData []byte
}

func main() {
	// Accessing a new cache table for the first time will create it.
	cache := cache2go.Cache("myCache")

	// We will put a new item in the cache. It will expire after
	// not being accessed via Value(key) for more than 5 seconds.
	val := myStruct{"This is a test!", []byte{}}
	cache.Add("someKey", 5*time.Second, &val)

	// Let's retrieve the item from the cache.
	res, err := cache.Value("someKey")
	if err == nil {
		fmt.Println("Found value in cache:", res.Data().(*myStruct).text)
	} else {
		fmt.Println("Error retrieving value from cache:", err)
	}

	// Wait for the item to expire in cache.
	time.Sleep(6 * time.Second)
	res, err = cache.Value("someKey")
	if err != nil {
		fmt.Println("Item is not cached (anymore).")
	}

	// Add another item that never expires.
	cache.Add("someKey", 0, &val)

	// cache2go supports a few handy callbacks and loading mechanisms.
	cache.SetAboutToDeleteItemCallback(func(e *cache2go.CacheItem) {
		fmt.Println("Deleting:", e.Key(), e.Data().(*myStruct).text, e.CreatedOn())
	})

	// Remove the item from the cache.
	cache.Delete("someKey")

	// And wipe the entire cache table.
	cache.Flush()
}

To run this example, go to examples/mycachedapp/ and run:

go run mycachedapp.go

You can find a few more examples here. Also see our test-cases in cache_test.go for further working examples.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].