ial.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. package cache
  17. import (
  18. "strings"
  19. "github.com/88250/lute/editor"
  20. "github.com/dgraph-io/ristretto"
  21. )
  22. var docIALCache, _ = ristretto.NewCache(&ristretto.Config{
  23. NumCounters: 102400,
  24. MaxCost: 10240,
  25. BufferItems: 64,
  26. })
  27. func PutDocIAL(p string, ial map[string]string) {
  28. docIALCache.Set(p, ial, 1)
  29. }
  30. func GetDocIAL(p string) (ret map[string]string) {
  31. ial, _ := docIALCache.Get(p)
  32. if nil == ial {
  33. return
  34. }
  35. ret = map[string]string{}
  36. for k, v := range ial.(map[string]string) {
  37. ret[k] = strings.ReplaceAll(v, editor.IALValEscNewLine, "\n")
  38. }
  39. return
  40. }
  41. func RemoveDocIAL(p string) {
  42. docIALCache.Del(p)
  43. }
  44. func ClearDocsIAL() {
  45. docIALCache.Clear()
  46. }
  47. var blockIALCache, _ = ristretto.NewCache(&ristretto.Config{
  48. NumCounters: 102400,
  49. MaxCost: 10240,
  50. BufferItems: 64,
  51. })
  52. func PutBlockIAL(id string, ial map[string]string) {
  53. blockIALCache.Set(id, ial, 1)
  54. }
  55. func GetBlockIAL(id string) (ret map[string]string) {
  56. ial, _ := blockIALCache.Get(id)
  57. if nil == ial {
  58. return
  59. }
  60. return ial.(map[string]string)
  61. }
  62. func RemoveBlockIAL(id string) {
  63. blockIALCache.Del(id)
  64. }
  65. func ClearBlocksIAL() {
  66. blockIALCache.Clear()
  67. }