Sha256: 08357e43ca6fa9ef1a16587ad2175907cf0e2e5a45c4f0cd04acd64d7db08e91

Contents?: true

Size: 679 Bytes

Versions: 1

Compression:

Stored size: 679 Bytes

Contents

# A simple cache for storing Textcaptcha answers, Rails.cache is used as the
# backend (ActiveSupport::Cache)

module ActsAsTextcaptcha
  class TextcaptchaCache

    KEY_PREFIX = 'acts_as_textcaptcha-'
    DEFAULT_EXPIRY_MINUTES = 10

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

    def read(key)
      Rails.cache.read(cache_key(key))
    end

    def delete(key)
      Rails.cache.delete(cache_key(key))
    end

    private

      def cache_key(key)
        "#{KEY_PREFIX}#{key}"
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_textcaptcha-4.4.1 lib/acts_as_textcaptcha/textcaptcha_cache.rb