A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 58 lines 1.4 kB view raw
1// SiYuan - Refactor your thinking 2// Copyright (c) 2020-present, b3log.org 3// 4// This program is free software: you can redistribute it and/or modify 5// it under the terms of the GNU Affero General Public License as published by 6// the Free Software Foundation, either version 3 of the License, or 7// (at your option) any later version. 8// 9// This program is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU Affero General Public License for more details. 13// 14// You should have received a copy of the GNU Affero General Public License 15// along with this program. If not, see <https://www.gnu.org/licenses/>. 16 17package cache 18 19import ( 20 "github.com/dgraph-io/ristretto" 21) 22 23type treeCacheEntry struct { 24 raw []byte 25} 26 27var ( 28 treeCache, _ = ristretto.NewCache(&ristretto.Config{ 29 NumCounters: 8, 30 MaxCost: 1024 * 1024 * 200, 31 BufferItems: 64, 32 }) 33) 34 35func GetTreeData(rootID string) (raw []byte, ok bool) { 36 v, _ := treeCache.Get(rootID) 37 if nil == v { 38 return nil, false 39 } 40 e := v.(*treeCacheEntry) 41 return e.raw, true 42} 43 44func SetTreeData(rootID string, raw []byte) { 45 if raw == nil { 46 return 47 } 48 entry := &treeCacheEntry{raw: raw} 49 treeCache.Set(rootID, entry, int64(len(raw))) 50} 51 52func RemoveTreeData(rootID string) { 53 treeCache.Del(rootID) 54} 55 56func ClearTreeCache() { 57 treeCache.Clear() 58}