Sha256: 37c82e5eb25664b9802834bd61411e47f8f73777f72f269df7a11bfa1ba400f9

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

begin
  require 'ehcache'
rescue LoadError => e
  $stderr.puts "You don't have ehcache installed in your application."
  $stderr.puts "Please add it to your Gemfile and run bundle install"
  raise e
end

module Ehcache
  # Mixin module providing facilities for the Rails 2 and Rails 3 Cache::Store
  # implementations.
  module Rails

    RAILS_CONFIG_DIR = File.join(RAILS_ROOT, 'config')

    DEFAULT_RAILS_CACHE_NAME = 'rails_cache'

    attr_reader :cache_manager

    def create_cache_manager(options)
      config = nil
      if options[:ehcache_config]
        Dir.chdir(RAILS_CONFIG_DIR) do
          config = File.expand_path(options[:ehcache_config])
        end
      else
        config = Ehcache::Config::Configuration.find(RAILS_CONFIG_DIR)
      end
      @cache_manager = Ehcache::CacheManager.create(config)
    end

    def create_cache(options)
      create_cache_manager(options) if @cache_manager.nil?

      @cache = @cache_manager.cache(options[:cache_name] || DEFAULT_RAILS_CACHE_NAME)
    end

    at_exit do
      @cache_manager.shutdown if @cache_manager
    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
jruby-ehcache-rails3-1.1.2 lib/ehcache/rails/ehcache_rails_common.rb
jruby-ehcache-rails2-1.1.2 lib/ehcache/rails/ehcache_rails_common.rb
jruby-ehcache-1.1.2 lib/ehcache/rails/ehcache_rails_common.rb