A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 81 lines 1.9 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 "strings" 21 22 "github.com/88250/lute/editor" 23 "github.com/dgraph-io/ristretto" 24) 25 26var docIALCache, _ = ristretto.NewCache(&ristretto.Config{ 27 NumCounters: 1024 * 100, 28 MaxCost: 1024 * 1024 * 200, 29 BufferItems: 64, 30}) 31 32func PutDocIAL(p string, ial map[string]string) { 33 docIALCache.Set(p, ial, 128) 34} 35 36func GetDocIAL(p string) (ret map[string]string) { 37 ial, _ := docIALCache.Get(p) 38 if nil == ial { 39 return 40 } 41 42 ret = map[string]string{} 43 for k, v := range ial.(map[string]string) { 44 ret[k] = strings.ReplaceAll(v, editor.IALValEscNewLine, "\n") 45 } 46 return 47} 48 49func RemoveDocIAL(p string) { 50 docIALCache.Del(p) 51} 52 53func ClearDocsIAL() { 54 docIALCache.Clear() 55} 56 57var blockIALCache, _ = ristretto.NewCache(&ristretto.Config{ 58 NumCounters: 1024 * 1000, 59 MaxCost: 1024 * 1024 * 200, 60 BufferItems: 64, 61}) 62 63func PutBlockIAL(id string, ial map[string]string) { 64 blockIALCache.Set(id, ial, 128) 65} 66 67func GetBlockIAL(id string) (ret map[string]string) { 68 ial, _ := blockIALCache.Get(id) 69 if nil == ial { 70 return 71 } 72 return ial.(map[string]string) 73} 74 75func RemoveBlockIAL(id string) { 76 blockIALCache.Del(id) 77} 78 79func ClearBlocksIAL() { 80 blockIALCache.Clear() 81}