Documentation ¶
Overview ¶
Package glc is provides the local cache which is stored in memoroy or file. This package creates `tmp` directory in case of using file cache.
Example:
mc := glc.NewMemoryCache(glc.DefaultMemoryCacheExpires) // Set if err := mc.Set("cacheKey", []byte('hoge')); err != nil { log.Fatal(err) } // Get data := mc.Get("cacheKey")
Index ¶
Constants ¶
View Source
const ( // DefaultMemoryCacheExpires is 60 seconds DefaultMemoryCacheExpires = 60 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileCache ¶
type FileCache struct {
// contains filtered or unexported fields
}
FileCache is cache data in local file.
func NewFileCache ¶ added in v1.2.0
NewFileCache returns FileCache pointer. If there is no temp directory named prefix, create temp directory for storing cache.
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item has cache item and expiration field.
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache is cache data in memory which has duration.
func NewMemoryCache ¶
func NewMemoryCache(d time.Duration) *MemoryCache
NewMemoryCache creates a new MemoryCache for given a its expires as time.Duration.
func (*MemoryCache) Get ¶
func (c *MemoryCache) Get(key string) []byte
Get returns a item or nil. If cache in local is nil or expiration date of the cache is earlier, this returns nil.
Click to show internal directories.
Click to hide internal directories.