Sha256: 9806bd27dc8304048b2826c073490c78e1f259e24c1b0ebf7218ebe0624bda56

Contents?: true

Size: 727 Bytes

Versions: 3

Compression:

Stored size: 727 Bytes

Contents

# frozen_string_literal: true

# A simple cache for storing Textcaptcha answers, Rails.cache is used as the
# backend (ActiveSupport::Cache). This must not be set as a `:null_store`.

module ActsAsTextcaptcha
  class TextcaptchaCache
    KEY_PREFIX = "acts_as_textcaptcha-"
    DEFAULT_EXPIRY_MINUTES = 10

    def write(key, value, options = {})
      options[:expires_in] = DEFAULT_EXPIRY_MINUTES.minutes unless options.has_key?(:expires_in)
      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

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_textcaptcha-4.7.0 lib/acts_as_textcaptcha/textcaptcha_cache.rb
acts_as_textcaptcha-4.6.0 lib/acts_as_textcaptcha/textcaptcha_cache.rb
acts_as_textcaptcha-4.5.2 lib/acts_as_textcaptcha/textcaptcha_cache.rb