lib/active_support/cache.rb in activesupport-7.1.2 vs lib/active_support/cache.rb in activesupport-7.1.3
- old
+ new
@@ -158,12 +158,12 @@
# popular cache store for large production websites.
#
# Some implementations may not support all methods beyond the basic cache
# methods of #fetch, #write, #read, #exist?, and #delete.
#
- # ActiveSupport::Cache::Store can store any Ruby object that is supported by
- # its +coder+'s +dump+ and +load+ methods.
+ # +ActiveSupport::Cache::Store+ can store any Ruby object that is supported
+ # by its +coder+'s +dump+ and +load+ methods.
#
# cache = ActiveSupport::Cache::MemoryStore.new
#
# cache.read('city') # => nil
# cache.write('city', "Duckburgh")
@@ -368,12 +368,12 @@
# end
# cache.fetch('city') # => "Duckburgh"
#
# ==== Options
#
- # Internally, +fetch+ calls #read_entry, and calls #write_entry on a cache
- # miss. Thus, +fetch+ supports the same options as #read and #write.
+ # Internally, +fetch+ calls +read_entry+, and calls +write_entry+ on a
+ # cache miss. Thus, +fetch+ supports the same options as #read and #write.
# Additionally, +fetch+ supports the following options:
#
# * <tt>force: true</tt> - Forces a cache "miss," meaning we treat the
# cache value as missing even if it's present. Passing a block is
# required when +force+ is true so this always results in a cache write.
@@ -816,11 +816,11 @@
else
@coder.dump(entry)
end
end
- def deserialize_entry(payload)
+ def deserialize_entry(payload, **)
payload.nil? ? nil : @coder.load(payload)
rescue DeserializationError
nil
end
@@ -1062,10 +1062,14 @@
write(name, result, options) unless result.nil? && options[:skip_nil]
result
end
end
+ # Enables the dynamic configuration of Cache entry options while ensuring
+ # that conflicting options are not both set. When a block is given to
+ # ActiveSupport::Cache::Store#fetch, the second argument will be an
+ # instance of +WriteOptions+.
class WriteOptions
def initialize(options) # :nodoc:
@options = options
end
@@ -1079,18 +1083,24 @@
def expires_in
@options[:expires_in]
end
+ # Sets the Cache entry's +expires_in+ value. If an +expires_at+ option was
+ # previously set, this will unset it since +expires_in+ and +expires_at+
+ # cannot both be set.
def expires_in=(expires_in)
@options.delete(:expires_at)
@options[:expires_in] = expires_in
end
def expires_at
@options[:expires_at]
end
+ # Sets the Cache entry's +expires_at+ value. If an +expires_in+ option was
+ # previously set, this will unset it since +expires_at+ and +expires_in+
+ # cannot both be set.
def expires_at=(expires_at)
@options.delete(:expires_in)
@options[:expires_at] = expires_at
end
end