GithubHelp home page GithubHelp logo

memcache's Introduction

memcache is a go package for memory cache

Quick Start

Install memcache

go get -u -v github.com/ohmountain/memcache

Use memcache

package main

import "time"
import "github.com/ohmountain/memcache"

func main() {
    // Use memcache without ttl
    cache := memcache.WithLRU(10000, false);
    cache.Set("Hello", "World");
    cache.Get("Hello")  // "World"
    cache.Get("world")  // nil 

    // Use memcache with ttl
    cache = memcache.WithLRU(10000, true)
    cache.SetExpire("Some", "Thing", 10)  // 10 seconds to live
    cache.Get("Some")  // "Thing"
    time.Sleep(11 * time.Second)
    cache.Get("Some")  // nil

    // Or delete
    cache.Set("Haha", "Huhu")
    cache.Delete("Haha") 
}

Difference between TTL and Non-TTL

If ttl is not used, it is just an LRU memory cache; if ttl is used, then it adds a mechanism of expiration by time on the basis of LRU, which means that even if the LRU mechanism does not take effect, the buffer will automatically clean up expired k/v.

memcache's People

Contributors

infinitete avatar ohmountain avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

infinitete

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.