Cache

package module
v0.0.0-...-a3076df Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

README

goCacheStore

Installation

Run go get github.com/Ankush-Hegde/goCacheStore from command line.

Usage

import (
	Cache "github.com/Ankush-Hegde/goCacheStore"
)
for database cache storage
DbEndpoint := UN:PASS@tcp(<IP>:<PORT>)/<DB>?parseTime=true&loc=Local
SessionLifetimeInSec := 1598453

_, cacheErr := Cache.MySQL(DbEndpoint, "tablename", "/", SessionLifetimeInSec, []byte("<SecretKey>"))

		if cacheErr != nil {
            		return cacheErr
		}
		if cacheErr != nil {
			defer Cache.DatabaseCacheStore.Close()
		}
for filebased cache storage
CacheFilePath := filepath.Join("path", "to_store_file")
SessionLifetimeInSec := 1598453

Cache.File(CacheFilePath, "/", SessionLifetimeInSec, []byte("<SecretKey>"))
below is the code to create, get and forget the cache data,
Cache.CacheStorage.New(key, data, time)

data := Cache.CacheStorage.Get(key)

Cache.CacheStorage.Forget(key)
note:-

key must be unique string,
data must be the map[string]interface{},
time must be the int in sec,

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	SessionKey  string
	SessionData string
	IpAdress    string
	UserAgent   string
	CreatedAt   time.Time
	ModifiedAt  time.Time
	ExpiresAt   time.Time
}

type FileCacheStore

type FileCacheStore struct {
	// contains filtered or unexported fields
}
var FilebaseCacheStore *FileCacheStore

func File

func File(cacheFilePath string, path string, maxAge int, keyPairs ...[]byte) *FileCacheStore

func (*FileCacheStore) Forget

func (s *FileCacheStore) Forget(key string) (bool, error)

func (*FileCacheStore) Get

func (s *FileCacheStore) Get(key string) (map[string]interface{}, error)

func (*FileCacheStore) New

func (s *FileCacheStore) New(key string, value map[string]interface{}, sessionLifeTime int) (bool, error)

type MySQLCacheStore

type MySQLCacheStore struct {
	// contains filtered or unexported fields
}
var DatabaseCacheStore *MySQLCacheStore

func MySQL

func MySQL(endpoint string, tableName string, path string, maxAge int, keyPairs ...[]byte) (*MySQLCacheStore, error)

func MySQLCacheStoreFromConnection

func MySQLCacheStoreFromConnection(db *sql.DB, tableName string, path string, maxAge int, keyPairs ...[]byte) (*MySQLCacheStore, error)

func (*MySQLCacheStore) Close

func (m *MySQLCacheStore) Close()

func (MySQLCacheStore) Forget

func (m MySQLCacheStore) Forget(session_key string) (bool, error)

func (MySQLCacheStore) Get

func (m MySQLCacheStore) Get(session_key string) (map[string]interface{}, error)

func (MySQLCacheStore) New

func (m MySQLCacheStore) New(session_key string, data map[string]interface{}, sessionLifeTime int) (bool, error)

type Store

type Store interface {
	New(string, map[string]interface{}, int) (bool, error)

	Get(string) (map[string]interface{}, error)

	Forget(string) (bool, error)
}
var CacheStorage Store

Jump to

Keyboard shortcuts

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