users can provide optional expression cache

This commit is contained in:
Michael Go
2025-01-07 14:32:46 -04:00
parent 2c7d686690
commit 42d822bda9
4 changed files with 47 additions and 4 deletions
+3 -1
View File
@@ -89,7 +89,9 @@ module Liquid
# Cache only exists during parsing
if cache
cache.fetch(markup) { inner_parse(markup, ss, cache).freeze }
return cache[markup] if cache.key?(markup)
cache[markup] = inner_parse(markup, ss, cache).freeze
else
inner_parse(markup, ss, nil).freeze
end
+4 -1
View File
@@ -15,7 +15,10 @@ module Liquid
# constructing new StringScanner in Lexer, Tokenizer, etc is expensive
# This StringScanner will be shared by all of them
@string_scanner = StringScanner.new("")
@expression_cache = LruRedux::Cache.new(10_000)
@expression_cache = if options[:expression_cache] != false
options[:expression_cache] || LruRedux::Cache.new(10_000)
end
self.depth = 0
self.partial = false