Class: PDF::Reader::ObjectCache

### Home Classes Methods

### In Files

- lib/pdf/reader/object_cache.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #each
- #each_key
- #each_pair
- #each_value
- #empty?
- #fetch
- #has_key?
- #has_value?
- #include?
- #key?
- #keys
- #length
- #member?
- #size
- #to_s
- #values

### Files

- MIT-LICENSE
- README.rdoc
- TODO
- mac_expert.txt
- mac_roman.txt
- pdf_doc.txt
- standard.txt
- symbol.txt
- win_ansi.txt
- zapf_dingbats.txt
- glyphlist.txt

### Class/Module Index

Quicksearch

- PDF
- PDF::Reader
- PDF::Reader::Buffer
- PDF::Reader::CidWidths
- PDF::Reader::EncryptedPDFError
- PDF::Reader::Filter
- PDF::Reader::Filter::Ascii85
- PDF::Reader::Filter::AsciiHex
- PDF::Reader::Filter::Depredict
- PDF::Reader::Filter::Flate
- PDF::Reader::Filter::Lzw
- PDF::Reader::Filter::Null
- PDF::Reader::Filter::RunLength
- PDF::Reader::Font
- PDF::Reader::FontDescriptor
- PDF::Reader::FormXObject
- PDF::Reader::InvalidObjectError
- PDF::Reader::MalformedPDFError
- PDF::Reader::ObjectCache
- PDF::Reader::ObjectHash
- PDF::Reader::PageLayout
- PDF::Reader::PageState
- PDF::Reader::PageTextReceiver
- PDF::Reader::Parser
- PDF::Reader::PrintReceiver
- PDF::Reader::Reference
- PDF::Reader::RegisterReceiver
- PDF::Reader::ResourceMethods
- PDF::Reader::StandardSecurityHandler
- PDF::Reader::Stream
- PDF::Reader::SynchronizedCache
- PDF::Reader::TextReceiver
- PDF::Reader::TextRun
- PDF::Reader::TransformationMatrix
- PDF::Reader::UnsupportedFeatureError
- PDF::Reader::WidthCalculator
- PDF::Reader::WidthCalculator::BuiltIn
- PDF::Reader::WidthCalculator::Composite
- PDF::Reader::WidthCalculator::TrueType
- PDF::Reader::WidthCalculator::TypeOneOrThree
- PDF::Reader::WidthCalculator::TypeZero
- PDF::Reader::XRef
- AFM
- AFM::Font

No matching classes.

# PDF::Reader::ObjectCache

A Hash-like object for caching commonly used objects from a PDF file.

This is an internal class, no promises about a stable API.

### Constants

CACHEABLE_TYPES

  These object types use little memory and are accessed a heap of times as part of random page access, so we'll cache the unmarshalled objects and avoid lots of repetitive (and expensive) tokenising

### Attributes

hits[R]
misses[R]

### Public Class Methods

new(lru_size = 1000) click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 19
    def initialize(lru_size = 1000)
      @objects = {}
      @lru_cache = Hashery::LRUHash.new(lru_size.to_i)
      @hits = 0
      @misses = 0
    end

### Public Instance Methods

[](key) click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 26
    def [](key)
      update_stats(key)
      @objects[key] || @lru_cache[key]
    end

[]=(key, value) click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 31
    def []=(key, value)
      if cacheable?(value)
        @objects[key] = value
      else
        @lru_cache[key] = value
      end
    end

each(&block) click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 44
    def each(&block)
      @objects.each(&block)
      @lru_cache.each(&block)
    end

Also aliased as: each_pair
each_key(&block) click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 50
    def each_key(&block)
      @objects.each_key(&block)
      @lru_cache.each_key(&block)
    end

each_pair(&block) click to toggle source
Alias for: each
each_value(&block) click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 55
    def each_value(&block)
      @objects.each_value(&block)
      @lru_cache.each_value(&block)
    end

empty?() click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 65
    def empty?
      @objects.empty? && @lru_cache.empty?
    end

fetch(key, local_default = nil) click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 39
    def fetch(key, local_default = nil)
      update_stats(key)
      @objects[key] || @lru_cache.fetch(key, local_default)
    end

has_key?(key) click to toggle source
Alias for: include?
has_value?(value) click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 76
    def has_value?(value)
      @objects.has_value?(value) || @lru_cache.has_value?(value)
    end

include?(key) click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 69
    def include?(key)
      @objects.include?(key) || @lru_cache.include?(key)
    end

Also aliased as: has_key?, key?, member?
key?(key) click to toggle source
Alias for: include?
keys() click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 84
    def keys
      @objects.keys + @lru_cache.keys
    end

length() click to toggle source
Alias for: size
member?(key) click to toggle source
Alias for: include?
size() click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 60
    def size
      @objects.size + @lru_cache.size
    end

Also aliased as: length
to_s() click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 80
    def to_s
      "<PDF::Reader::ObjectCache size: #{self.size}>"
    end

values() click to toggle source

    # File lib/pdf/reader/object_cache.rb, line 88
    def values
      @objects.values + @lru_cache.values
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.