Browse files

jruby compatibility of disc cache. jruby throws IOError instead of

  • Loading branch information...
1 parent 6acc0f8 commit 58b98ac040aae07c92ea4d2f7e108098c8fc2128 Daniel Mendler committed with Dec 18, 2009
Showing with 10 additions and 7 deletions.
  1. +10 −7 lib/rack/cache/metastore.rb
17 lib/rack/cache/metastore.rb
@@ -214,23 +214,26 @@ def initialize(root="/tmp/rack-cache/meta-#{ARGV[0]}")
def read(key)
path = key_path(key), 'rb') { |io| Marshal.load(io) }
- rescue Errno::ENOENT
+ rescue Errno::ENOENT, IOError
def write(key, entries)
- path = key_path(key)
-, 'wb') { |io| Marshal.dump(entries, io, -1) }
- rescue Errno::ENOENT
- Dir.mkdir(File.dirname(path), 0755)
- retry
+ tries = 0
+ begin
+ path = key_path(key)
+, 'wb') { |io| Marshal.dump(entries, io, -1) }
+ rescue Errno::ENOENT, IOError
+ Dir.mkdir(File.dirname(path), 0755)
+ retry if (tries += 1) == 1
+ end
def purge(key)
path = key_path(key)
- rescue Errno::ENOENT
+ rescue Errno::ENOENT, IOError

2 comments on commit 58b98ac


Hi Ryan, thank you for merging this. I am following jruby and they committet a fix to adapt the jruby behaviour in the case of missing parent folders to MRI (JRUBY-4380, but I am not sure in the case of unlink). This change could be removed with next jruby release. But we could also keep it to be prepared for the case of real io errors to fail gracefully. But I think a failing rack-cache is not the problem then :)



Oh good. I'd rather like to remove it if possible, since IOErrors should really bubble up out of rack-cache IMO. Errno::ENOENT is an expected condition when the file's directory hasn't yet been created. IOErrors are exception conditions and should definitely raise out.

Please sign in to comment.