Categorygithub.com/farzai/cache-go
modulepackage
0.0.0-20230803064113-eb8797a7e989
Repository: https://github.com/farzai/cache-go.git
Documentation: pkg.go.dev

# README

Cache - GO

A simple cache library for golang.

Installation

go get github.com/farzai/cache-go

Usage

package main

import (
	"fmt"
	"time"

	"github.com/farzai/cache-go"
)


func main() {
	cache := cache.NewCache(cache.NewRedisDriver("localhost:6379", "", 0, 10*time.Second))
	// Or
	// cache := cache.NewCache(cache.NewMemoryDriver(10*time.Second))
	// cache := cache.NewCache(cache.NewLocalFileDriver("/storage/cache", 10*time.Second))

	err := cache.Set("key", "value")
	if err != nil {
		fmt.Println("Error setting value in cache:", err)
		return
	}

	value, err := cache.Get("key")
	if err != nil {
		fmt.Println("Error getting value from cache:", err)
		return
	}

	fmt.Println("Value from cache:", value)
}

License

Please see the LICENSE file for more information.

# Functions

NewOptimizedRedisDriver creates a new OptimizedRedisDriver instance.
NewOptimizedRedisDriverWithOptions creates a new OptimizedRedisDriver instance with the specified options.
NewRedisDriver creates a new RedisDriver instance.
NewRedisDriverWithOptions creates a new RedisDriver instance with the specified options.

# Structs

CacheItem represents a single cache item.
OptimizedRedisDriver implements the Cache interface using Redis as the storage driver with performance optimizations.
RedisDriver implements the Cache interface using Redis as the storage driver.

# Interfaces

Cache interface defines the methods for interacting with the cache.