gomemcache

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Go Mem Cache

This repository is a Go module for creating a memory cache with a specified capacity and key eviction policy.

Overview

db.go provides a set of functions to perform operations on a memory cache. It uses the container/heap and sync packages from the Go standard library.

Types

  • DB: The main type representing the memory cache.
  • KeyEvictionPolicy: A type used for setting the eviction policy.
  • Option: A type for optional configuration functions.

Functions

  • New(): This function creates a new memory cache.
  • WithKeyEvictionPolicy(): This function sets the key eviction policy for the memory cache.
  • WithCapacity(): This function sets the capacity for the memory cache.
  • GetCapacity(): This function gets the capacity of the memory cache.
  • GetKeyEvictionPolicy(): This function gets the key eviction policy of the memory cache.
  • GetKeys(): This function gets all the keys in the memory cache.
  • Get(): This function gets an item from the memory cache.
  • SetWithExpiry(): This function sets an item in the memory cache with a specified expiry.
  • Set(): This function sets an item in the memory cache.
  • Size(): This function gets the size of the memory cache.

Usage

To use this module, import it in your Go code:

import "github.com/Atoo35/go-mem-cache"

Then, you can call its functions like this:

    // Configurable options.
    db := gomemcache.New()

    db.Set("key", "value", 1)
    value, err := db.Get("key")

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](opts ...Option[T]) *DB[T]

func (*DB[T]) Get

func (db *DB[T]) Get(key string) (T, error)

func (*DB[T]) GetCapacity

func (db *DB[T]) GetCapacity() int64

Getter functions

func (*DB[T]) GetKeyEvictionPolicy

func (db *DB[T]) GetKeyEvictionPolicy() types.KeyEvictionPolicy

func (*DB[T]) GetKeys

func (c *DB[T]) GetKeys() []string

func (*DB[T]) Set

func (db *DB[T]) Set(key string, value T, priority int64)

func (*DB[T]) SetWithExpiry

func (db *DB[T]) SetWithExpiry(key string, value T, priority, expiry int64)

func (*DB[T]) Size

func (db *DB[T]) Size() int64

type Option

type Option[T any] func(*DB[T])

func WithCapacity

func WithCapacity[T any](capacity int64) Option[T]

func WithKeyEvictionPolicy

func WithKeyEvictionPolicy[T any](keyEvictionPolicy types.KeyEvictionPolicy) Option[T]

Option functions

Directories

Path Synopsis
src

Jump to

Keyboard shortcuts

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