Sha256: 6554eed624c02a1864b3e470393e7a6c12712a89bb8456824e780ad2c2582811

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

=begin
    Copyright 2010-2015 Tasos Laskos <tasos.laskos@arachni-scanner.com>

    This file is part of the Arachni Framework project and is subject to
    redistribution and commercial restrictions. Please see the Arachni Framework
    web site for more information on licensing and terms of use.
=end

module Arachni
module Support::Cache

# Random Replacement cache implementation.
#
# Better suited for low-latency operations, discards entries at random
# in order to make room for new ones.
#
# @author Tasos "Zapotek" Laskos <tasos.laskos@arachni-scanner.com>
class Preference < Base

    # Storage method
    #
    # @param    [Object]    k
    #   Entry key.
    # @param    [Object]    v
    #   Object to store.
    #
    # @return   [Object]
    #   `v`
    def store( k, v )
        prune if capped? && (size > max_size - 1)
        cache[make_key( k )] = v
    end

    def prefer( &block )
        @preference = block
    end

    private

    def find_preference
        @preference.call
    end

    def prune
        preferred = find_preference
        delete( preferred ) if preferred
    end

end

end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
arachni-1.3.2 lib/arachni/support/cache/preference.rb
arachni-1.3.1 lib/arachni/support/cache/preference.rb
arachni-1.3 lib/arachni/support/cache/preference.rb
arachni-1.2.1 lib/arachni/support/cache/preference.rb
arachni-1.2 lib/arachni/support/cache/preference.rb