Skip to content

Instantly share code, notes, and snippets.

@s4l1h
Created October 16, 2016 14:03
Show Gist options
  • Select an option

  • Save s4l1h/caad66bc09f29d9bfe65e58ca307a221 to your computer and use it in GitHub Desktop.

Select an option

Save s4l1h/caad66bc09f29d9bfe65e58ca307a221 to your computer and use it in GitHub Desktop.
import "errors"
var (
errorNotFound = errors.New("Cache Datası Bulunamadı: ")
errorEmptyKey = errors.New("Key Boş Olamaz")
)
// MemoryCache In memory'de data saklama sınıfı
type MemoryCache struct {
data map[string][]byte
}
// NewMemoryCache Yeni bir memory cache oluşturur
func NewMemoryCache() Cache {
return &MemoryCache{}
}
// Name : Cache Provider Adını döndürür
func (c *MemoryCache) Name() string {
return "MemoryCache"
}
// Get : İn Memory'de tutulan datayı alır.
func (c *MemoryCache) Get(key string) ([]byte, error) {
if value, oke := c.data[key]; oke == true {
return value, nil
}
return []byte(""), errorNotFound
}
// Set : İn Memorye datayı kaydeder
func (c *MemoryCache) Set(key string, data []byte) error {
if key == "" {
return errorEmptyKey
}
c.data[key] = data
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment