class MarkdownCache::Renderer
Constants
- EXPIRE
Public Instance Methods
render(text)
click to toggle source
# File lib/markdown_cache/renderer.rb, line 8 def render(text) return "" if text.nil? from_cache(key(Digest::SHA1.hexdigest(text))) do kramdown_render(text) end end
Private Instance Methods
from_cache(key) { |self| ... }
click to toggle source
# File lib/markdown_cache/renderer.rb, line 28 def from_cache(key, &block) if (value = redis.get(key)).nil? value = yield(self) redis.set(key, Marshal.dump(value)) redis.expire(key, EXPIRE) value else Marshal.load(value) end end
key(sha)
click to toggle source
# File lib/markdown_cache/renderer.rb, line 39 def key(sha) "markdown:#{sha}" end
kramdown_options()
click to toggle source
# File lib/markdown_cache/renderer.rb, line 21 def kramdown_options { input: 'GFM', syntax_highlighter: 'rouge' } end
kramdown_render(text)
click to toggle source
# File lib/markdown_cache/renderer.rb, line 17 def kramdown_render(text) Kramdown::Document.new(text, kramdown_options).to_html end
redis()
click to toggle source
# File lib/markdown_cache/renderer.rb, line 43 def redis MarkdownCache.configuration.redis end