modulepackage
0.0.0-20240413183556-fe07fafd6ed1
Repository: https://github.com/cmparrela/go-db-inmemory.git
Documentation: pkg.go.dev
# README
Cacher
Cacher is a simple in-memory database replication tool developed in Go. It provides methods for managing key-value data in memory, including List
, Get
, Set
, and Delete
.
Features
- In-Memory Database: Cacher stores key-value pairs in memory for fast access.
- Expiration: Records inserted into the memory have an expiration date. The software automatically removes expired records from memory at the appropriate time.
Usage
- Import the Cacher package in your Go code:
import "github.com/cmparrela/go-db-inmemory/cache"
- Create a new Cacher instance:
cacher := cache.NewCacher()
- Use the provided methods to manage data:
// Set a key-value pair with an expiration time of 10 minutes
expiration := time.Duration(rand.Intn(10)) * time.Second
cacher.Set("key", "value", expiration)
// Get the value associated with a key
value := cache.Get("key")
// Delete a key-value pair
cache.Delete("key")
// List all key-value pairs in the cache
allData := cache.List()
Example
package main
import (
"context"
"github.com/cmparrela/go-db-inmemory/cache"
"github.com/google/uuid"
"math/rand"
"time"
)
func main() {
ctx := context.Background()
cacher := cache.NewCacher()
for i := 1; i < 1000000; i++ {
expiration := time.Duration(rand.Intn(10)) * time.Second
key := uuid.New().String()
cacher.Set(key, "teste", expiration)
}
<-ctx.Done()
}
# Packages
No description provided by the author