1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/vendor/github.com/koding/cache/memory_nots.go

40 lines
896 B
Go
Raw Normal View History

package cache
// MemoryNoTS provides a non-thread safe caching mechanism
type MemoryNoTS struct {
// items holds the cache data
items map[string]interface{}
}
// NewMemoryNoTS creates MemoryNoTS struct
func NewMemoryNoTS() *MemoryNoTS {
return &MemoryNoTS{
items: map[string]interface{}{},
}
}
// Get returns a value of a given key if it exists
// and valid for the time being
func (r *MemoryNoTS) Get(key string) (interface{}, error) {
value, ok := r.items[key]
if !ok {
return nil, ErrNotFound
}
return value, nil
}
// Set will persist a value to the cache or
// override existing one with the new one
func (r *MemoryNoTS) Set(key string, value interface{}) error {
r.items[key] = value
return nil
}
// Delete deletes a given key, it doesnt return error if the item is not in the
// system
func (r *MemoryNoTS) Delete(key string) error {
delete(r.items, key)
return nil
}