lib/convenient_service/support/cache.rb in convenient_service-0.2.1 vs lib/convenient_service/support/cache.rb in convenient_service-0.3.0
- old
+ new
@@ -23,10 +23,20 @@
##
# @return [Boolean]
#
# @internal
+ # https://ruby-doc.org/core-2.7.0/Hash.html#method-i-empty-3F
+ #
+ def empty?
+ hash.empty?
+ end
+
+ ##
+ # @return [Boolean]
+ #
+ # @internal
# https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-exist-3F
#
def exist?(key)
hash.has_key?(key)
end
@@ -96,9 +106,25 @@
#
def fetch(key, &block)
return read(key) unless block
exist?(key) ? read(key) : write(key, block.call)
+ end
+
+ ##
+ # @return [ConvenientService::Support::Cache]
+ #
+ def clear
+ hash.clear
+
+ self
+ end
+
+ ##
+ # @return [ConvenientService::Support::Cache]
+ #
+ def scope(key)
+ fetch(key) { Support::Cache.new }
end
##
# @return [ConvenientService::Support::Cache::Key]
#