Sha256: 5960ab173eb32e710562e230f8c9cfa0dab0ba90b9bf17f1ebae3f3e2399e671

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 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 =
        if defined?(::Rails)
          File.join(::Rails.root.to_s, 'config')
        elsif defined?(RAILS_ROOT)
          File.join(RAILS_ROOT, 'config')
        end

    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

2 entries across 2 versions & 2 rubygems

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