Class: TRuby::ParseCache
- Inherits:
-
Object
- Object
- TRuby::ParseCache
- Defined in:
- lib/t_ruby/cache.rb
Overview
AST parse tree cache
Instance Method Summary collapse
- #get(source) ⇒ Object
-
#initialize(memory_cache: nil, file_cache: nil) ⇒ ParseCache
constructor
A new instance of ParseCache.
- #invalidate(source) ⇒ Object
- #set(source, parse_result) ⇒ Object
- #stats ⇒ Object
Constructor Details
#initialize(memory_cache: nil, file_cache: nil) ⇒ ParseCache
Returns a new instance of ParseCache.
187 188 189 190 |
# File 'lib/t_ruby/cache.rb', line 187 def initialize(memory_cache: nil, file_cache: nil) @memory_cache = memory_cache || MemoryCache.new(max_size: 500) @file_cache = file_cache end |
Instance Method Details
#get(source) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/t_ruby/cache.rb', line 192 def get(source) key = source_key(source) # Try memory first result = @memory_cache.get(key) return result if result # Try file cache if @file_cache result = @file_cache.get(key) if result @memory_cache.set(key, result) return result end end nil end |
#invalidate(source) ⇒ Object
220 221 222 223 224 |
# File 'lib/t_ruby/cache.rb', line 220 def invalidate(source) key = source_key(source) @memory_cache.delete(key) @file_cache&.delete(key) end |
#set(source, parse_result) ⇒ Object
211 212 213 214 215 216 217 218 |
# File 'lib/t_ruby/cache.rb', line 211 def set(source, parse_result) key = source_key(source) @memory_cache.set(key, parse_result) @file_cache&.set(key, parse_result) parse_result end |
#stats ⇒ Object
226 227 228 |
# File 'lib/t_ruby/cache.rb', line 226 def stats @memory_cache.stats end |