Repository: rails/rails
File: activesupport/lib/active_support/cache/strategy/local_cache.rb (Ruby)

Code before:
          def write_entry(key, entry)
            @data[key] = entry
            true
          end

          def delete_entry(key)
            !!@data.delete(key)
          end

          def fetch_entry(key) # :nodoc:
            @data.fetch(key) { @data[key] = yield }
          end
        end

        # Use a local cache for the duration of block.
        def with_local_cache(&block)
          use_temporary_local_cache(LocalStore.new, &block)
        end

        # Set a new local cache.
        def new_local_cache
          LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new)
        end

        # Unset the current local cache.
        def clear_local_cache
          LocalCacheRegistry.set_cache_for(local_cache_key, nil)
        end

        # The current local cache.
        def local_cache
          LocalCacheRegistry.cache_for(local_cache_key)
        end

        # Middleware class can be inserted as a Rack handler to be local cache for the
        # duration of request.
        def middleware
          @middleware ||= Middleware.new("ActiveSupport::Cache::Strategy::LocalCache", self)
        end

        def clear(options = nil) # :nodoc:
          return super unless cache = local_cache
          cache.clear(options)
          super
        end

        def cleanup(options = nil) # :nodoc:
          return super unless cache = local_cache
          cache.clear(options)
          super
        end

Review comment (performance):
`clear` is perhaps a bit ambiguous here. It can easily be understood as "empty the cache but keep it active" given that's what `Rails.cache.clear` does.

Maybe `unset` or `disable` ?

Code after:
          def write_entry(key, entry)
            @data[key] = entry
            true
          end

          def delete_entry(key)
            !!@data.delete(key)
          end

          def fetch_entry(key) # :nodoc:
            @data.fetch(key) { @data[key] = yield }
          end
        end

        # Use a local cache for the duration of block.
        def with_local_cache(&block)
          use_temporary_local_cache(LocalStore.new, &block)
        end

        # Set a new local cache.
        def new_local_cache
          LocalCacheRegistry.set_cache_for(local_cache_key, LocalStore.new)
        end

        # Unset the current local cache.
        def unset_local_cache
          LocalCacheRegistry.set_cache_for(local_cache_key, nil)
        end

        # The current local cache.
        def local_cache
          LocalCacheRegistry.cache_for(local_cache_key)
        end

        # Middleware class can be inserted as a Rack handler to be local cache for the
        # duration of request.
        def middleware
          @middleware ||= Middleware.new("ActiveSupport::Cache::Strategy::LocalCache", self)
        end

        def clear(options = nil) # :nodoc:
          return super unless cache = local_cache
          cache.clear(options)
          super
        end

        def cleanup(options = nil) # :nodoc:
          return super unless cache = local_cache
          cache.clear(options)
          super
        end