Esempio n. 1
0
//initialize cache
func init() {
	//cache manager that will intermediate all operations for cache store/read.
	cacheManager := cache.SimpleCacheManager{
		CacheStorage: cache.NewRedisCacheStorage("localhost:6379", "", 8, 200, 3000, "lab", cache.SerializerGOB{}),
	}

	//start cache spot reference.
	cacheSpot = aop.CacheSpot{
		HotFunc:      FindProduct,        // concrete FindProduct function
		CachedFunc:   &CachedFindProduct, // Empty cached function as ref. Will receive a swap function
		CacheManager: cacheManager,       // Cache Manager implementation
		WaitingGroup: &sync.WaitGroup{},
	}.MustStartCache() // Validate function signatures, assoaciate swap to CachedFunc
}
	"encoding/gob"
	"strconv"
	"testing"
	"time"

	"fmt"
	"github.com/darciopacifico/enablecache/cache"
	"github.com/op/go-logging"
	"math/rand"
	"os"
	"sync"
)

var (
	cacheAreaAuto     = "dyna_test:" + strconv.Itoa(int(time.Now().Unix()))
	cacheStorageRedis = cache.NewRedisCacheStorage("localhost:6379", "", 8, 200, 2000, cacheAreaAuto, cache.SerializerGOB{})
	cmAuto            = cache.SimpleCacheManager{
		CacheStorage: cacheStorageRedis,
	}
)

func init() {

	format := logging.MustStringFormatter("%{color}%{time:15:04:05.000} PID:%{pid} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}")
	backend1 := logging.NewLogBackend(os.Stdout, "", 0)
	backend1Formatter := logging.NewBackendFormatter(backend1, format)
	logging.SetBackend(backend1Formatter)

	logging.SetLevel(logging.DEBUG, "cache")

}
	"sync"
	"testing"
)

type UserEmail struct {
	Email string
	Name  string
	Uuid  string
}

func (u UserEmail) GetCacheKey() string {
	return "User:"******"localhost:6379", "", 8, 200, 2000, "str_test", cache.SerializerGOB{})
	cmStr   = cache.SimpleCacheManager{
		CacheStorage: csRedis,
	}

	cs CacheSpot
)

var CFindByEmail func(email string) UserEmail

func init() {

	cs = CacheSpot{
		CachedFunc:   &CFindByEmail,
		HotFunc:      FindByEmail,
		Ttl:          100,
package aop

import (
	"math/rand"
	"strconv"
	"time"

	"github.com/darciopacifico/enablecache/cache"
)

var (
	cacheStorage = cache.NewRedisCacheStorage("localhost:6379", "", 8, 200, 2000, strconv.Itoa(rand.Int()), cache.SerializerGOB{})
	cacheManager = cache.SimpleCacheManager{
		CacheStorage: cacheStorage,
	}
)

func init() {

}

type User struct {
	Id       int
	Name     string
	Creation time.Time
	Ttl      int
}

func (u User) GetTtl() int {
	return u.Ttl
}