cache

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 3 Imported by: 4

README

gFly Caching

Copyright © 2023, gFly
https://www.gFly.dev
All rights reserved.
Usage

Install

go get -u github.com/gflydev/cache@v1.0.1

Quick usage main.go

import (
    cacheRedis "github.com/gflydev/cache/redis"
    "github.com/gflydev/cache"
)

// Register Redis cache
cache.Register(cacheRedis.New())

// Set cache 15 days
if err = cache.Set(key, value, time.Duration(15*24*3600) * time.Second); err != nil {
    log.Errorf("Error %q", err)
}

val, err := cache.Get(key)
if err != nil {
    log.Errorf("Error %q", err)
}

// Delete 
if err = cache.Del(key); err != nil {
    log.Errorf("Error %q", err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Del added in v1.0.1

func Del(key string) error

func Get added in v1.0.1

func Get(key string) (interface{}, error)

func Key

func Key(key string) string

Key wrapper key

func Register added in v1.0.1

func Register(c ICache)

Register assign cache manager

func Set added in v1.0.1

func Set(key string, value interface{}, expiration time.Duration) error

Types

type ICache

type ICache interface {
	Set(key string, value interface{}, expiration time.Duration) error
	Get(key string) (interface{}, error)
	Del(key string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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