Sha256: 86476e9c753d5cd6177aa516828fcf94ef9987efabe1c008c0f03323fad2966c

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

# Common code used in the ehcache_store implementations for ActiveSupport 2.x and 3.x
require 'active_support'

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

# Base class for both the ActiveSupport 2 & 3 implementations
module Ehcache
  class ActiveSupportStore < ActiveSupport::Cache::Store

    cattr_accessor :config_directory
    cattr_accessor :default_cache_name

    attr_reader :cache_manager

    def create_cache_manager(options = {})
      config_dir = self.class.config_directory
      config = if options[:ehcache_config]
        File.expand_path(File.join(config_dir, options[:ehcache_config]))
      else
        Ehcache::Config::Configuration.find(config_dir) if config_dir
      end
      # Ehcache will use the failsafe configuration if nothing is passed in
      # Note: .create is a factory method
      @cache_manager = Ehcache::CacheManager.create(config)
    end

    def create_cache(options = {})
      create_cache_manager(options) if @cache_manager.nil?
      @cache_manager.cache(options[:cache_name] || default_cache_name)
    end

    def default_cache_name
      self.class.default_cache_name || 'app_cache'
    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.2.0 lib/ehcache/active_support_store.rb
jruby-ehcache-rails2-1.2.0 lib/ehcache/active_support_store.rb