Class: Jekyll::Quicklatex::Block::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/quicklatex.rb

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jekyll/quicklatex.rb', line 24

def initialize
  @cache = {}
  @cache_file = 'latex.cache'
  if File.exist? @cache_file
    File.open(@cache_file, 'r') do |f|
      while line = f.gets
        hash, url = line.split
        @cache[hash] = url
      end
    end
  end
end

Instance Method Details

#cache(content, url) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/jekyll/quicklatex.rb', line 42

def cache(content, url)
  id = hash_id(content)
  @cache[id] = url
  File.open(@cache_file, 'a') do |f|
    f.syswrite("#{id} #{url}\n")
  end
end

#fetch(content) ⇒ Object



37
38
39
40
# File 'lib/jekyll/quicklatex.rb', line 37

def fetch(content)
  id = hash_id(content)
  @cache[id]
end