Class: Jekyll::Quicklatex::Block::Cache
- Inherits:
-
Object
- Object
- Jekyll::Quicklatex::Block::Cache
- Defined in:
- lib/jekyll/quicklatex.rb
Instance Method Summary collapse
- #cache(content, url) ⇒ Object
- #fetch(content) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize ⇒ Cache
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 |