OSDN Git Service

add fast sync func (#204)
[bytom/vapor.git] / federation / database / cache.go
1 package database
2
3 import (
4         "github.com/golang/groupcache/lru"
5
6         "github.com/vapor/federation/database/orm"
7 )
8
9 const maxAssetCached = 1024
10
11 type AssetCache struct {
12         lruCache *lru.Cache
13 }
14
15 func NewAssetCache() *AssetCache {
16         return &AssetCache{lruCache: lru.New(maxAssetCached)}
17 }
18
19 func (a *AssetCache) Add(assetID string, asset *orm.Asset) {
20         a.lruCache.Add(assetID, asset)
21 }
22
23 func (a *AssetCache) Get(assetID string) *orm.Asset {
24         if v, ok := a.lruCache.Get(assetID); ok {
25                 return v.(*orm.Asset)
26         }
27
28         return nil
29 }
30
31 func (a *AssetCache) Remove(assetID string) {
32         a.lruCache.Remove(assetID)
33 }