Class: Rack::Cache::EntityStore::FILE

### Home Classes Methods

### In Files

- lib/rack/cache/entitystore.rb

### Parent

Rack::Cache::EntityStore

### Methods

- ::new
- ::resolve
- #body_path
- #exist?
- #open
- #purge
- #read
- #spread
- #storage_path
- #write

### Files

- CHANGES
- COPYING
- README
- TODO

### Class/Module Index

Quicksearch

- Rack
- Rack::Cache
- Rack::Cache::AppEngine
- Rack::Cache::AppEngine::MC
- Rack::Cache::AppEngine::MemCache
- Rack::Cache::CacheControl
- Rack::Cache::Context
- Rack::Cache::EntityStore
- Rack::Cache::EntityStore::DISK
- Rack::Cache::EntityStore::Dalli
- Rack::Cache::EntityStore::Disk
- Rack::Cache::EntityStore::FILE
- Rack::Cache::EntityStore::GAE
- Rack::Cache::EntityStore::GAECACHE
- Rack::Cache::EntityStore::GAEStore
- Rack::Cache::EntityStore::HEAP
- Rack::Cache::EntityStore::Heap
- Rack::Cache::EntityStore::MEM
- Rack::Cache::EntityStore::MemCacheBase
- Rack::Cache::EntityStore::MemCached
- Rack::Cache::Key
- Rack::Cache::MetaStore
- Rack::Cache::MetaStore::DISK
- Rack::Cache::MetaStore::Dalli
- Rack::Cache::MetaStore::Disk
- Rack::Cache::MetaStore::FILE
- Rack::Cache::MetaStore::GAE
- Rack::Cache::MetaStore::GAECACHE
- Rack::Cache::MetaStore::GAEStore
- Rack::Cache::MetaStore::HEAP
- Rack::Cache::MetaStore::Heap
- Rack::Cache::MetaStore::MEM
- Rack::Cache::MetaStore::MemCacheBase
- Rack::Cache::MetaStore::MemCached
- Rack::Cache::Options
- Rack::Cache::Request
- Rack::Cache::Response
- Rack::Cache::Storage

No matching classes.

# Rack::Cache::EntityStore::FILE

Stores entity bodies on disk at the specified path.

### Attributes

root[R]

Path where entities should be stored. This directory is created the first time the store is instansiated if it does not already exist.

### Public Class Methods

new(root) click to toggle source

    # File lib/rack/cache/entitystore.rb, line 90
    def initialize(root)
      @root = root
      FileUtils.mkdir_p root, :mode => 0755
    end

### Protected Class Methods

resolve(uri) click to toggle source

    # File lib/rack/cache/entitystore.rb, line 162
    def self.resolve(uri)
      path = File.expand_path(uri.opaque || uri.path)
      new path
    end

### Public Instance Methods

exist?(key) click to toggle source

    # File lib/rack/cache/entitystore.rb, line 95
    def exist?(key)
      File.exist?(body_path(key))
    end

open(key) click to toggle source

Open the entity body and return an IO object. The IO object's each method is overridden to read 8K chunks instead of lines.

    # File lib/rack/cache/entitystore.rb, line 116
    def open(key)
      Body.open(body_path(key), 'rb')
    rescue Errno::ENOENT
      nil
    end

purge(key) click to toggle source

    # File lib/rack/cache/entitystore.rb, line 140
    def purge(key)
      File.unlink body_path(key)
      nil
    rescue Errno::ENOENT
      nil
    end

read(key) click to toggle source

    # File lib/rack/cache/entitystore.rb, line 99
    def read(key)
      File.open(body_path(key), 'rb') { |f| f.read }
    rescue Errno::ENOENT
      nil
    end

write(body, ttl=nil) click to toggle source

    # File lib/rack/cache/entitystore.rb, line 122
    def write(body, ttl=nil)
      filename = ['buf', $$, Thread.current.object_id].join('-')
      temp_file = storage_path(filename)
      key, size =
        File.open(temp_file, 'wb') { |dest|
          slurp(body) { |part| dest.write(part) }
        }

      path = body_path(key)
      if File.exist?(path)
        File.unlink temp_file
      else
        FileUtils.mkdir_p File.dirname(path), :mode => 0755
        FileUtils.mv temp_file, path
      end
      [key, size]
    end

### Protected Instance Methods

body_path(key) click to toggle source

    # File lib/rack/cache/entitystore.rb, line 158
    def body_path(key)
      storage_path spread(key)
    end

spread(key) click to toggle source

    # File lib/rack/cache/entitystore.rb, line 152
    def spread(key)
      key = key.dup
      key[2,0] = '/'
      key
    end

storage_path(stem) click to toggle source

    # File lib/rack/cache/entitystore.rb, line 148
    def storage_path(stem)
      File.join root, stem
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.