Giter Club home page Giter Club logo

quixote's Introduction

Quixote: Caching at windmills

GoDoc

Sometimes you want a cache to reduce the number of calls you make to a service dependency, and sometimes you want a cache to reduce the impact of an unreliable service dependency. Sometimes you want both.

Quixote is an in-process cache supporting oldest-first cache eviction with a two-stage invalidation policy. The first stage is a "soft" invalidation, in which the cached value will be used only if no fresh value can be produced by the service dependency. The second stage is "hard" invalidation, in which the cached value is purged from the cache.

Using two stages like this allows cached values to be kept arbitrarily fresh while the service dependency is available. In the extreme case, the soft invalidation time can be set to zero, so that Quixote will return cached values only in the case of the service dependency being unavailable.

Installation

go get github.com/cpdupuis/Quixote/quixote

Usage

This example shows a program that prints the result of calling a service. The result is cached, with a soft expiry after 10 seconds, and a hard expiry after 15 minutes. The cache has a maximum size of 256 items.

func callService(params string) (string,bool) {
    // Call a service, return the result as a string, as well as a boolean ok value
}

func main() {
    cache := quixote.MakeQuixoteCache(callService, 10 * time.Second, 15 * time.Minute, 256)
    for {
        result,ok := cache.Get("testing 123")
        if ok {
            // Use result
        }
    }
}

quixote's People

Contributors

cpdupuis avatar quasilyte avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.