Class: PictureTag::Cache
- Inherits:
-
Object
- Object
- PictureTag::Cache
- Defined in:
- lib/jekyll_picture_tag/cache.rb
Overview
Store expensive bits of information between text files. Originally cached width & heights of images in addition to digests, now just image digests.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(base_name) ⇒ Cache
constructor
A new instance of Cache.
-
#write ⇒ Object
Call after updating data.
Constructor Details
#initialize(base_name) ⇒ Cache
Returns a new instance of Cache.
7 8 9 |
# File 'lib/jekyll_picture_tag/cache.rb', line 7 def initialize(base_name) @base_name = base_name end |
Instance Method Details
#[](key) ⇒ Object
11 12 13 |
# File 'lib/jekyll_picture_tag/cache.rb', line 11 def [](key) data[key] end |
#[]=(key, value) ⇒ Object
15 16 17 18 19 |
# File 'lib/jekyll_picture_tag/cache.rb', line 15 def []=(key, value) raise ArgumentError unless template.keys.include? key data[key] = value end |
#write ⇒ Object
Call after updating data.
22 23 24 25 26 27 28 29 30 |
# File 'lib/jekyll_picture_tag/cache.rb', line 22 def write return if PictureTag.config['disable_disk_cache'] FileUtils.mkdir_p(File.join(base_directory, sub_directory)) File.open(filename, 'w+') do |f| f.write JSON.generate(data) end end |