Created
February 22, 2010 16:12
-
-
Save julik/311203 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "digest" | |
# Instead of storing cached fragments in pages/widgets/2345567/description it will instead make an MD5 of | |
# each fragment name and save them in directories spread evenly, with no more than 256 directories at once. | |
# This will prevent the filesystem from going totally medieval on you after widget 4568977 has been created and | |
# cached. | |
class FragmentedStore < ActiveSupport::Cache::FileStore | |
def delete(name, options=nil) | |
super(path_to_digest_tree(name), options) | |
end | |
def exist?(name) | |
super(path_to_digest_tree(name)) | |
end | |
def read(name, options = nil) | |
super(path_to_digest_tree(name), options) | |
end | |
def write(name, value, options = nil) | |
super(path_to_digest_tree(name), value, options) | |
end | |
private | |
def path_to_digest_tree(name) | |
Digest::MD5.hexdigest(Marshal.dump(name)).scan(/(.{2})/).join('/') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment