Sha256: ec1f533489dd6f3059cbe06845e4b339cac4934c9cf3ffd364fb9bc61a3c8820

Contents?: true

Size: 883 Bytes

Versions: 7

Compression:

Stored size: 883 Bytes

Contents

# A simple cache for storing Textcaptcha answers
# by default the underlying cache implementation is
# the standard Rails.cache (ActiveSupport::Cache)

module ActsAsTextcaptcha
  class TextcaptchaCache

    CACHE_KEY_PREFIX = 'acts_as_textcaptcha-'
    DEFAULT_CACHE_EXPIRY_MINUTES = 10

    def write(key, value, options = {})
      unless options.has_key?(:expires_in)
        options[:expires_in] = DEFAULT_CACHE_EXPIRY_MINUTES.minutes
      end
      Rails.cache.write(cache_key(key), value, options)
    end

    def read(key, options = nil)
      Rails.cache.read(cache_key(key), options)
    end

    def delete(key, options = nil)
      Rails.cache.delete(cache_key(key), options)
    end

    private

    # since this cache may be shared with other objects
    # a prefix is used in all cache keys
    def cache_key(key)
      "#{CACHE_KEY_PREFIX}#{key}"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
acts_as_textcaptcha-4.3.0 lib/acts_as_textcaptcha/textcaptcha_cache.rb
acts_as_textcaptcha-4.2.0 lib/acts_as_textcaptcha/textcaptcha_cache.rb
acts_as_textcaptcha-4.1.3 lib/acts_as_textcaptcha/textcaptcha_cache.rb
acts_as_textcaptcha-4.1.2 lib/acts_as_textcaptcha/textcaptcha_cache.rb
acts_as_textcaptcha-4.1.1 lib/acts_as_textcaptcha/textcaptcha_cache.rb
acts_as_textcaptcha-4.1.0 lib/acts_as_textcaptcha/textcaptcha_cache.rb
acts_as_textcaptcha-4.0.0 lib/acts_as_textcaptcha/textcaptcha_cache.rb