lib/zache.rb in zache-0.13.1 vs lib/zache.rb in zache-0.13.2

- old
+ new

@@ -1,10 +1,10 @@ # frozen_string_literal: true # (The MIT License) # -# Copyright (c) 2018-2023 Yegor Bugayenko +# Copyright (c) 2018-2024 Yegor Bugayenko # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the 'Software'), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -32,11 +32,11 @@ # # For more information read # {README}[https://github.com/yegor256/zache/blob/master/README.md] file. # # Author:: Yegor Bugayenko (yegor256@gmail.com) -# Copyright:: Copyright (c) 2018-2023 Yegor Bugayenko +# Copyright:: Copyright (c) 2018-2024 Yegor Bugayenko # License:: MIT class Zache # Fake implementation that doesn't cache anything, but behaves like it # does. It implements all methods of the original class, but doesn't do # any caching. This is very useful for testing. @@ -153,11 +153,11 @@ lifetime: lifetime } end end - # Removes the value from the hash, by the provied key. If the key is absent + # Removes the value from the cache, by the provided key. If the key is absent # and the block is provided, the block will be called. def remove(key) synchronized { @hash.delete(key) { yield if block_given? } } end @@ -175,10 +175,14 @@ end end # Remove keys that are expired. def clean - synchronized { @hash.delete_if { |_key, value| expired?(value) } } + synchronized { @hash.delete_if { |key, _value| expired?(key) } } + end + + def empty? + @hash.empty? end private def calc(key, lifetime)