Giter Site home page Giter Site logo

gofast's Introduction

gofast

gofast is a Go module that provides easy-to-use in-memory cache algorithms like LRU (Least Recently Used). It allows you to import and use these algorithms simply and directly in your Go projects.

Installation

Install gofast by simply using the go get command:

$ go get github.com/raghavgh/gofast

Usage

Importing the module

First, import gofast like this:

import "github.com/raghavgh/gofast"

Here is an example of how you can use the module:

type CacheRepo struct {
    MetaCache gofast.Cache
}

func NewCacheRepo() *CacheRepo {
    return &CacheRepo{
        // 1 is the algorithm type for LRU
        MetaCache: gofast.NewCache(1000, gofast.LRU),
    }
}

Available Functions

// Get returns the value (if any) and a boolean representing whether the value was found or not
Get(key string) (any, bool)
// Put adds a value to the cache
Put(key string, val any)
// Remove removes a value from the cache
Remove(key string)
// Len returns the number of elements of the cache
Len() int
// Clear clears the cache
Clear()
// Contains returns true if the cache contains the given key
Contains(key string) bool

**All above funtions are thread safe

Available Cache Algorithms

Currently, the following cache algorithms are available:

  1. LRU (Least Recently Used)

  2. LFU (Least Frequently Used)

  3. LIFO (Last In, First Out)

More algorithms will be available in future versions.

Supported algorithms can be specified with the following constants:

gofast.LRU   // Least Recently Used algorithm
gofast.LFU   // Least Frequently Used algorithm
gofast.FIFO  // First In, First Out algorithm
gofast.MRU   // Most Recently Used algorithm
gofast.RR    // Random Replacement algorithm
gofast.SLRU  // Segmented Least Recently Used algorithm
gofast.LIFO  // Last In, First Out algorithm

Contributions

More details regarding contributing will be provided soon. We look forward to your valuable inputs!

gofast's People

Contributors

raghavgh avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.