Skip to content

Commit

Permalink
Verify that the cache directory exists before trying to store a respo…
Browse files Browse the repository at this point in the history
…nse. Closes #12
  • Loading branch information
seancribbs committed Sep 27, 2009
1 parent 209c327 commit 3682d66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,8 @@

=== Edge

* Verify that the cache directory exists before trying to store a response.
[Sean Cribbs]
* Fix page-part deletion in JS. [Sean Cribbs]
* Don't cache extension-defined javascripts, but do cache the defaults.
[Sean Cribbs]
Expand Down
12 changes: 12 additions & 0 deletions lib/radiant/cache.rb
Expand Up @@ -37,6 +37,12 @@ def initialize(root="#{Rails.root}/tmp/cache/entity")
def clear
Dir[File.join(self.root, "*")].each {|file| FileUtils.rm_rf(file) }
end

def write(body)
# Verify that the cache directory exists before attempting to write
FileUtils.mkdir_p(self.root, :mode => 0755) unless File.directory?(self.root)
super
end
end

class MetaStore < Rack::Cache::MetaStore::Disk
Expand All @@ -49,6 +55,12 @@ def clear
Dir[File.join(self.root, "*")].each {|file| FileUtils.rm_rf(file) }
end

def store(request, response, entitystore)
# Verify that the cache directory exists before attempting to store
FileUtils.mkdir_p(self.root, :mode => 0755) unless File.directory?(self.root)
super
end

private
def restore_response(hash, body=nil)
# Cribbed from the Rack::Cache source
Expand Down

0 comments on commit 3682d66

Please sign in to comment.