Class: RubyScope::SexpCache

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_scope/sexp_cache.rb

Defined Under Namespace

Classes: CacheEntry

Constant Summary collapse

DB =
DBM

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ SexpCache

Returns a new instance of SexpCache.



6
7
8
# File 'lib/ruby_scope/sexp_cache.rb', line 6

def initialize(root)
  @root = root
end

Instance Method Details

#[](path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby_scope/sexp_cache.rb', line 10

def [] path
  with_cache do |cache|
    entry = cache[path]
    entry = Marshal.load(entry) if entry
    
    if entry && entry.last_modified == last_modified(path)
      entry.sexp
    else
      cache.delete path
      nil
    end
  end
end

#[]=(path, value) ⇒ Object



24
25
26
27
28
29
# File 'lib/ruby_scope/sexp_cache.rb', line 24

def []= path,value
  with_cache do |cache|
    entry = CacheEntry.new(last_modified(path), value)
    cache[path] = Marshal.dump(entry)
  end
end

#cache_pathObject



31
32
33
# File 'lib/ruby_scope/sexp_cache.rb', line 31

def cache_path
  @cache_path ||= File.join(@root,'.ruby_scope.cache')
end