Fetching contributors…
Cannot retrieve contributors at this time
52 lines (41 sloc) 1.05 KB
// Copyright 2015 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xorm
import (
var _ core.CacheStore = NewMemoryStore()
// MemoryStore represents in-memory store
type MemoryStore struct {
store map[interface{}]interface{}
mutex sync.RWMutex
// NewMemoryStore creates a new store in memory
func NewMemoryStore() *MemoryStore {
return &MemoryStore{store: make(map[interface{}]interface{})}
// Put puts object into store
func (s *MemoryStore) Put(key string, value interface{}) error {
defer s.mutex.Unlock()[key] = value
return nil
// Get gets object from store
func (s *MemoryStore) Get(key string) (interface{}, error) {
defer s.mutex.RUnlock()
if v, ok :=[key]; ok {
return v, nil
return nil, ErrNotExist
// Del deletes object
func (s *MemoryStore) Del(key string) error {
defer s.mutex.Unlock()
delete(, key)
return nil