Cookie Consent by Free Privacy Policy Generator 📌 Golang in-memory key-value pair cache


✅ Golang in-memory key-value pair cache


💡 Newskategorie: Programmierung
🔗 Quelle: dev.to

Hello devs, I am excited to share my most recent project.
I started working on this Golang project about a week ago. And as you must have guessed already, yes, it's yet another Golang library :)
Fs-cache is a Golang-based caching solution that's simple and lightweight. It supports data caching with optional parameters for expiration. This library has 14 methods added to it to allow for different use cases of the library.
Fs-cache provides a quick way to store and retrieve frequently accessed data, significantly enhancing your application performance and reducing database queries / API calls.
Below is a sample code on how to use the library.

Installation

go get github.com/iqquee/fs-cache@latest

Import

fscache "github.com/iqquee/fs-cache"

Usage

Debug()

Debug() enables debug to get certain logs

fs := fscache.New()
// set if you want to get logs of activities
fs.Debug()

Set()

Set() adds a new data into the in-memmory storage

fs := fscache.New()

// the third param is an optional param used to set the expiration time of the set data
if err := fs.Set("key1", "user1", 5*time.Minute); err != nil {
    fmt.Println("error setting key1:", err)
}

Get()

Get() retrieves a data from the in-memmory storage

fs := fscache.New()

result, err := fs.Get("key1")
if err != nil {
    fmt.Println("error getting key 1:", err)
}

fmt.Println("key1:", result)

SetMany()

SetMany() sets many data objects into memory for later access

fs := fscache.New()

testCase := []map[string]fscache.CacheData{
    {
        "key4": fscache.CacheData{
            Value:    "value4",
            Duration: time.Now().Add(time.Minute),
        },
        "key5": fscache.CacheData{
            Value: false,
        },
    },
}

setMany, err := fs.SetMany(testCase)
if err != nil {
    fmt.Println("error setMany:", err)
}
fmt.Println("setMany:", setMany)

GetMany()

GetMany() retrieves datas with matching keys from the in-memmory storage

fs := fscache.New()

keys := []string{"key1", "key2"}

getMany := fs.GetMany(keys)
fmt.Println("getMany:", getMany)

OverWrite()

OverWrite() updates an already set value using it key

fs := fscache.New()

if err := fs.OverWrite("key1", "overwrite1", 1*time.Minute); err != nil {
    fmt.Println("error overwriting:", err)
}

OverWriteWithKey()

OverWriteWithKey() updates an already set value and key using the previously set key

fs := fscache.New()

if err := fs.OverWriteWithKey("previousKey", "newKey", "newValue", 1*time.Minute); err != nil {
    fmt.Println("error overWriteWithKey:", err)
}

Del()

Del() deletes a data from the in-memmory storage

fs := fscache.New()

if err := fs.Del("key1"); err != nil {
    fmt.Println("error deleting key 1:", err)
}

TypeOf()

TypeOf() returns the data type of a value

fs := fscache.New()

typeOf, err := fs.TypeOf("key1")
if err != nil {
    fmt.Println("error typeOf:", err)
}
fmt.Println("typeOf:", typeOf)

Clear()

Clear() deletes all datas from the in-memmory storage

fs := fscache.New()

if err := fs.Clear(); err != nil {
    fmt.Println("error clearing all datas:", err)
}

Size()

Size() retrieves the total data objects in the in-memmory storage

fs := fscache.New()

size := fs.Size()
fmt.Println("total size: ", size)

Keys()

Keys() returns all the keys in the storage

fs := fscache.New()

keys := fs.Keys()
fmt.Println("keys: ", keys)

Values()

Values() returns all the values in the storage

fs := fscache.New()

values := fs.Values()
fmt.Println("values: ", values)

KeyValuePairs()

KeyValuePairs() returns an array of key-value pairs of all the data in the storage

fs := fscache.New()

keyValuePairs := fs.KeyValuePairs()
fmt.Println("keyValuePairs: ", keyValuePairs)

This sample code above shows how easy it is to use this library in your Golang projects. You can check out fs-cache on GitHub.

...

✅ How to Pair Amazon Fire TV Stick to Rumble Pair Code [rumble.com/pair: Pair Rumble and Enter Code]


📈 56.01 Punkte

✅ Cache-Control, Netlify-CDN-Cache-Control, Cache Invalidation, Oh My


📈 29.35 Punkte

✅ WP Super Cache Plugin up to 1.7.1 on WordPress Cache Settings wp-cache-config.php cache_path code injection


📈 29.35 Punkte

✅ Pair the integers of Array so that each pair sum is consecutive and distinct


📈 28.01 Punkte

✅ How to Fix Openload Pair olpair.com/pair Error


📈 28.01 Punkte

✅ GoLang JWT Authentication Using Golang Gin Framework with MongoDB


📈 24.79 Punkte

✅ How to use GoLang in Flutter Application - Golang FFI


📈 24.79 Punkte

✅ GitHub Security Lab: Golang : Improvements to Golang SSRF query


📈 24.79 Punkte

✅ (Part 8)Golang Framework Hands-on - Cache/Params Data Caching and Data Parameters


📈 22.18 Punkte

✅ How to create an SSH RSA Key Pair and Connect to a Remote Host


📈 20.52 Punkte

✅ Bouncy Castle BC/BC-FJA RSA Key Pair Generator weak encryption


📈 20.52 Punkte

✅ Amazon EC2 key pair + 2FA


📈 20.52 Punkte

✅ Bouncy Castle BC/BC-FJA RSA Key Pair Generator schwache Verschlüsselung


📈 20.52 Punkte

✅ Hacking and Linux Go Together Like 2 Keys in a Key Pair


📈 20.52 Punkte

✅ wipe cache partition - So leert man den Android-Cache


📈 19.57 Punkte

✅ Estratégias de cache | Cache Strategies


📈 19.57 Punkte

✅ Cache: Google schließt Kuba an sein Global Cache Network an


📈 19.57 Punkte

✅ CVE-2020-10112 | Citrix Gateway 11.1/12.0/12.1 Cache Cache Poisoning request smuggling (ID 156660)


📈 19.57 Punkte

✅ Cache: Google schließt Kuba an sein Global Cache Network an


📈 19.57 Punkte

✅ How to Cache Expensive Database Queries Using the Momento Serverless Cache


📈 19.57 Punkte

✅ 3D V-Cache Technology: AMD stapelt L3-Cache bei Ryzen auf 192 MByte


📈 19.57 Punkte

✅ 3D V-Cache Technology: AMD stapelt L3-Cache bei Ryzen auf 192 MByte


📈 19.57 Punkte

✅ Jack-in-the-Cache: A New Code injection Technique through Modifying X86-to-ARM Translation Cache


📈 19.57 Punkte

✅ Medium CVE-2020-28275: Cache-base project Cache-base


📈 19.57 Punkte

✅ AWS S3 Crypto SDK for GoLang prior V2 AES-GCM Key risky encryption


📈 18.92 Punkte

✅ Autenticação REST via API KEY em Golang


📈 18.92 Punkte

✅ CVE-2020-10941 | ARM mbed TLS up to 2.6.14 Cache Key missing encryption (DLA 3249-1)


📈 16.3 Punkte

✅ Ansible up to 1.2.0 SSH Host Key Cache Man-in-the-Middle unknown vulnerability


📈 16.3 Punkte

✅ Researchers demonstrate cache-like atacks against rsa key exchange.


📈 16.3 Punkte

✅ Russian Telegrab malware harvesting Telegram Desktop credentials, cookies, desktop cache, and key files


📈 16.3 Punkte











matomo

Datei nicht gefunden!