Module: Airbrake::FileCache Private

Defined in:
lib/airbrake-ruby/file_cache.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Extremely simple global cache.

Since:

  • v2.4.1

Constant Summary collapse

MAX_SIZE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns:

  • (Integer)

Since:

  • v2.4.1

50
MUTEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns:

  • (Mutex)

Since:

  • v2.4.1

Mutex.new

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Retrieve an object from the cache.

Parameters:

  • key (Object)

Returns:

  • (Object)

    the corresponding value

Since:

  • v2.4.1



30
31
32
33
34
# File 'lib/airbrake-ruby/file_cache.rb', line 30

def self.[](key)
  MUTEX.synchronize do
    data[key]
  end
end

.[]=(key, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Associates the value given by value with the key given by key. Deletes entries that exceed MAX_SIZE.

Parameters:

  • key (Object)
  • value (Object)

Returns:

  • (Object)

    the corresponding value

Since:

  • v2.4.1



19
20
21
22
23
24
# File 'lib/airbrake-ruby/file_cache.rb', line 19

def self.[]=(key, value)
  MUTEX.synchronize do
    data[key] = value
    data.delete(data.keys.first) if data.size > MAX_SIZE
  end
end

.empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks whether the cache is empty. Needed only for the test suite.

Returns:

  • (Boolean)

Since:

  • v2.4.1



39
40
41
# File 'lib/airbrake-ruby/file_cache.rb', line 39

def self.empty?
  data.empty?
end

.resetvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Since:

  • v4.7.0



45
46
47
# File 'lib/airbrake-ruby/file_cache.rb', line 45

def self.reset
  @data = {}
end