Class: Resourceful::FileCacheManager
- Inherits:
-
AbstractCacheManager
- Object
- AbstractCacheManager
- Resourceful::FileCacheManager
- Defined in:
- lib/resourceful/cache_manager.rb
Overview
Stores cache entries in a directory on the filesystem. Similarly to the InMemoryCacheManager there are no limits on storage, so this will eventually eat up all your disk!
Instance Method Summary collapse
-
#initialize(location = "/tmp/resourceful") ⇒ FileCacheManager
constructor
Create a new FileCacheManager.
- #invalidate(uri) ⇒ Object
- #lookup(request) ⇒ Object
- #store(request, response) ⇒ Object
Constructor Details
#initialize(location = "/tmp/resourceful") ⇒ FileCacheManager
Create a new FileCacheManager
98 99 100 101 102 |
# File 'lib/resourceful/cache_manager.rb', line 98 def initialize(location="/tmp/resourceful") require 'fileutils' require 'yaml' @dir = FileUtils.mkdir_p(location) end |
Instance Method Details
#invalidate(uri) ⇒ Object
118 119 120 |
# File 'lib/resourceful/cache_manager.rb', line 118 def invalidate(uri); File.unlink(cache_file(uri)); end |
#lookup(request) ⇒ Object
104 105 106 107 108 |
# File 'lib/resourceful/cache_manager.rb', line 104 def lookup(request) response = cache_entries_for(request)[request] response. = false if response response end |
#store(request, response) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/resourceful/cache_manager.rb', line 110 def store(request, response) return unless response.cacheable? entries = cache_entries_for(request) entries[request] = response File.open(cache_file(request.uri), "w") {|fh| fh.write( YAML.dump(entries) ) } end |