cache

package
v0.0.0-...-83dca6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2022 License: MIT Imports: 2 Imported by: 0

README

GoCryptoTrader package cache

Build Status Software License GoDoc Coverage Status Go Report Card

This cache package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progress on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Current Features for cache package

  • Basic LRU cache system with both goroutine safe (via mutex locking) and non-goroutine safe options

How to use

Basic Usage:
package main

import ("github.com/thrasher-corp/gocryptotrader/common/cache")

func main() {
	lruCache := cache.New(5)
	lruCache.Add("hello", "world")
	c := lruCache.Contains("hello")
	if !c {
		fmt.Println("expected cache to contain \"hello\" key")
	}

	v := lruCache.Get("hello")
	if v == nil {
		fmt.Println("expected cache to contain \"hello\" key")
	}
	fmt.Println(v)
}

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRU

type LRU struct {
	Cap uint64
	// contains filtered or unexported fields
}

LRU non-thread safe fixed size LRU cache

func NewLRUCache

func NewLRUCache(capacity uint64) *LRU

NewLRUCache returns a new non-concurrent-safe LRU cache with input capacity

func (*LRU) Add

func (l *LRU) Add(key, value interface{})

Add adds a value to the cache

func (*LRU) Clear

func (l *LRU) Clear()

Clear is used to completely clear the cache.

func (*LRU) Contains

func (l *LRU) Contains(key interface{}) (f bool)

Contains check if key is in cache this does not update LRU

func (*LRU) Get

func (l *LRU) Get(key interface{}) interface{}

Get returns keys value from cache if found

func (*LRU) Len

func (l *LRU) Len() uint64

Len returns length of l

func (*LRU) Remove

func (l *LRU) Remove(key interface{}) bool

Remove removes key from the cache, if the key was removed.

type LRUCache

type LRUCache struct {
	// contains filtered or unexported fields
}

LRUCache thread safe fixed size LRU cache

func New

func New(capacity uint64) *LRUCache

New returns a new concurrent-safe LRU cache with input capacity

func (*LRUCache) Add

func (l *LRUCache) Add(k, v interface{})

Add new entry to Cache return true if entry removed

func (*LRUCache) Clear

func (l *LRUCache) Clear()

Clear is used to clear the cache.

func (*LRUCache) Contains

func (l *LRUCache) Contains(key interface{}) bool

Contains checks if cache contains key

func (*LRUCache) ContainsOrAdd

func (l *LRUCache) ContainsOrAdd(key, value interface{}) bool

ContainsOrAdd checks if cache contains key if not adds to cache

func (*LRUCache) Get

func (l *LRUCache) Get(key interface{}) (value interface{})

Get looks up a key's value from the cache.

func (*LRUCache) Len

func (l *LRUCache) Len() uint64

Len returns the number of items in the cache.

func (*LRUCache) Remove

func (l *LRUCache) Remove(key interface{}) bool

Remove entry from cache

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL