hoitekcache

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: MIT Imports: 2 Imported by: 0

README ¶

Hoitek-Cache

Build Status Coverage Status contributions welcome

Hoitek-Cache is a simple multi-driver cache library for Golang. It is designed to be simple to use and easy to integrate into your project.

Features 🔥

  • Multi-driver support
  • Easy to use
  • Complete API Reference
  • 100% Test Coverage

Installation

You can install Hoitek-Cache using composer:

go get github.com/hoitek-go/hoitek-cache

Usage

Basic Usage
package main

import (
	hoitekcache "github.com/hoitek-go/hoitek-cache"
	"github.com/hoitek-go/hoitek-cache/config"
	"github.com/hoitek-go/hoitek-cache/drivers"
	"github.com/hoitek-go/hoitek-cache/versions"
	"log"
)

func main() {
	// Create a new cache instance
	cache := hoitekcache.Connect(hoitekcache.Driver[drivers.Redis, config.Redis]{
		Config: config.Redis{
			Version:  versions.REDIS_V7,
			Host:     "localhost",
			Port:     6379,
			Password: "",
			Database: 0,
		},
	})
	defer cache.Close()

	// Set a value
	cache.Set("foo", "bar")

	// Get a value
	value, err := cache.Get("foo")
	if err != nil {
		log.Fatal(err)
	}
	log.Println(value)

	// Delete a value
	err = cache.Delete("foo")
	if err != nil {
		log.Fatal(err)
	}
}
Redis Driver Support
cache := hoitekcache.Connect(hoitekcache.Driver[drivers.Redis, config.Redis]{
    Config: config.Redis{
        Version:  versions.REDIS_V7,
        Host:     "localhost",
        Port:     6379,
        Password: "",
        Database: 0,
    },
})
MongoDB Driver Support
cache := hoitekcache.Connect(hoitekcache.Driver[drivers.MongoDB, config.MongoDB]{
    Config: config.MongoDB{
       Host: "localhost",
       Port:     27017,
       Username: "root",
       Password: "111111",
       Database: "cachedb",
    },
})
API Reference
Connect[T1 ports.DriverType, T2 ports.ConfigType](driver Driver[T1, T2]) *Gach[T1, T2]
Set(key string, value interface{}) error
Get(key string) (interface{}, error)
Delete(key string) error
Exists(key string) (bool, error)
Expire(key string, seconds int) error
TTL(key string) (int, error)
Flush() error
Close() error
Ping() error

Run Tests

  make test

Export Test Coverage

  make testcov

Tech Stack

Server: Golang

Licence

MIT License

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Driver ¶

type Driver[T1 ports.DriverType, T2 ports.ConfigType] struct {
	Config T2
	// contains filtered or unexported fields
}

type Gach ¶

type Gach[T1 ports.DriverType, T2 ports.ConfigType] struct {
	Driver Driver[T1, T2]
}

func Connect ¶

func Connect[T1 ports.DriverType, T2 ports.ConfigType](driver Driver[T1, T2]) *Gach[T1, T2]

func (*Gach[T1, T2]) Close ¶

func (g *Gach[T1, T2]) Close() error

func (*Gach[T1, T2]) Delete ¶

func (g *Gach[T1, T2]) Delete(key string) error

func (*Gach[T1, T2]) Exists ¶

func (g *Gach[T1, T2]) Exists(key string) (bool, error)

func (*Gach[T1, T2]) Expire ¶

func (g *Gach[T1, T2]) Expire(key string, seconds int) error

func (*Gach[T1, T2]) Flush ¶

func (g *Gach[T1, T2]) Flush() error

func (*Gach[T1, T2]) Get ¶

func (g *Gach[T1, T2]) Get(key string) (interface{}, error)

func (*Gach[T1, T2]) GetConfig ¶

func (g *Gach[T1, T2]) GetConfig() T2

func (*Gach[T1, T2]) GetConfigType ¶

func (g *Gach[T1, T2]) GetConfigType() ports.ConfigType

func (*Gach[T1, T2]) GetDriver ¶

func (g *Gach[T1, T2]) GetDriver() T1

func (*Gach[T1, T2]) GetDriverType ¶

func (g *Gach[T1, T2]) GetDriverType() ports.DriverType

func (*Gach[T1, T2]) Ping ¶

func (g *Gach[T1, T2]) Ping() error

func (*Gach[T1, T2]) Set ¶

func (g *Gach[T1, T2]) Set(key string, value interface{}) error

func (*Gach[T1, T2]) SetConfig ¶

func (g *Gach[T1, T2]) SetConfig(config T2)

func (*Gach[T1, T2]) SetDriver ¶

func (g *Gach[T1, T2]) SetDriver(driver T1)

func (*Gach[T1, T2]) TTL ¶

func (g *Gach[T1, T2]) TTL(key string) (int, error)

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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