Created
October 16, 2016 14:03
-
-
Save s4l1h/caad66bc09f29d9bfe65e58ca307a221 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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