Class: Cachetastic::Adapters::HtmlFile

Inherits:
FileBase show all
Defined in:
lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/html_file.rb

Instance Attribute Summary

Attributes inherited from FileBase

#directory, #hashed_keys

Attributes inherited from Base

#logger, #name

Instance Method Summary collapse

Methods inherited from FileBase

#delete, #expire_all, #setup, #stats, #valid?

Methods inherited from Base

configuration, #configuration, #debug?, #initialize, #stats

Constructor Details

This class inherits a constructor from Cachetastic::Adapters::Base

Instance Method Details

#get(key) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/html_file.rb', line 23

def get(key)
  full_path = full_path_from_dir(get_key_directoy(key, false))
  return nil unless File.exists?(full_path)
  so = html_to_store_object(File.open(full_path).read)
  if so
    if so.invalid?
      self.delete(key)
      return nil
    end
    return so.value
  end
  return nil
end

#set(key, value, expiry = 0) ⇒ Object



37
38
39
40
41
42
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/html_file.rb', line 37

def set(key, value, expiry = 0)
  so = Cachetastic::Adapters::StoreObject.new(key.to_s, value, expiry)
  File.open(full_path_from_key(key), "w") do |f|
    f.puts store_object_to_html(so)
  end
end