Sha256: d24de87d863e33a484c89c6cf3abe40b4a1a8fb9febf8d426f9e0655171345eb

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

=begin
    Copyright 2010-2014 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.
#
# Discards entries at random in order to make room for new ones.
#
# @author Tasos "Zapotek" Laskos <tasos.laskos@arachni-scanner.com>
class RandomReplacement < Base

    # @see Arachni::Cache::Base#initialize
    def initialize( * )
        super
        @keys = []
    end

    # @see Arachni::Cache::Base#store
    def store( k, v )
        already_in = include?( k )

        super( k, v )
    ensure
        @keys << k if !already_in
    end

    def clear
        super
        @keys.clear
    end

    private

    def prune_candidate
        @keys.delete_at( rand( size ) )
    end

    def prune
        delete( prune_candidate )
    end

end

end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
arachni-1.0.6 lib/arachni/support/cache/random_replacement.rb
arachni-1.0.5 lib/arachni/support/cache/random_replacement.rb
arachni-1.0.4 lib/arachni/support/cache/random_replacement.rb
arachni-1.0.3 lib/arachni/support/cache/random_replacement.rb
arachni-1.0.2 lib/arachni/support/cache/random_replacement.rb
arachni-1.0.1 lib/arachni/support/cache/random_replacement.rb
arachni-1.0 lib/arachni/support/cache/random_replacement.rb