Class Cachetastic::Adapters::File
In: lib/cachetastic/adapters/file.rb
Parent: Cachetastic::Adapters::FileBase

This adapter uses the file system as it‘s backing. The configuration for this should look something like this:

 my_awesome_cache_options:
   debug: false
   adapter: file
   marshall_method: none
   default_expiry: <%= 24.hours %>
   store_options:
     dir: /usr/local/caches/
   logging:
     logger_1:
       type: file
       file: log/file_store_cache.log

Methods

get   set   store_file_name  

Constants

STORE_FILE_NAME = "cache.yml"

Public Instance methods

[Source]

    # File lib/cachetastic/adapters/file.rb, line 16
16:   def get(key)
17:     full_path = full_path_from_dir(get_key_directoy(key, false))
18:     return nil unless File.exists?(full_path)
19:     so = YAML::load(File.open(full_path).read)
20:     if so
21:       if so.invalid?
22:         self.delete(key)
23:         return nil
24:       end
25:       if so.value.is_a?(YAML::Object)
26:         require so.value.class.underscore
27:         so = YAML::load(File.open(full_path).read)
28:       end
29:       return so.value
30:     end
31:     return nil
32:   end

[Source]

    # File lib/cachetastic/adapters/file.rb, line 34
34:   def set(key, value, expiry = 0)
35:     so = Cachetastic::Adapters::StoreObject.new(key.to_s, value, expiry)
36:     File.open(full_path_from_key(key), "w") do |f|
37:       f.puts YAML.dump(so)
38:     end
39:   end

Protected Instance methods

[Source]

    # File lib/cachetastic/adapters/file.rb, line 42
42:   def store_file_name
43:     return STORE_FILE_NAME
44:   end

[Validate]