class PDF::Reader::SynchronizedCache

Throughout the pdf-reader codebase, repeated calculations which can benefit from caching are made In some cases, caching and reusing results can not only save CPU cycles but also greatly reduce memory requirements But at the same time, we don't want to throw away thread safety We have two interchangeable thread-safe cache implementations:

Public Class Methods

new() click to toggle source
# File lib/pdf/reader/synchronized_cache.rb, line 21
def initialize
  @cache = {}
  @mutex = Mutex.new
end

Public Instance Methods

[](key) click to toggle source
# File lib/pdf/reader/synchronized_cache.rb, line 25
def [](key)
  @mutex.synchronize { @cache[key] }
end
[]=(key,value) click to toggle source
# File lib/pdf/reader/synchronized_cache.rb, line 28
def []=(key,value)
  @mutex.synchronize { @cache[key] = value }
end