context_cache.go 835 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2018 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package xorm
  5. // ContextCache is the interface that operates the cache data.
  6. type ContextCache interface {
  7. // Put puts value into cache with key.
  8. Put(key string, val interface{})
  9. // Get gets cached value by given key.
  10. Get(key string) interface{}
  11. }
  12. type memoryContextCache map[string]interface{}
  13. // NewMemoryContextCache return memoryContextCache
  14. func NewMemoryContextCache() memoryContextCache {
  15. return make(map[string]interface{})
  16. }
  17. // Put puts value into cache with key.
  18. func (m memoryContextCache) Put(key string, val interface{}) {
  19. m[key] = val
  20. }
  21. // Get gets cached value by given key.
  22. func (m memoryContextCache) Get(key string) interface{} {
  23. return m[key]
  24. }