Class: PDF::Reader::ObjectCache

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader/object_cache.rb

Overview

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

This is an internal class used by PDF::Reader::ObjectHash

Constant Summary collapse

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

[:Catalog, :Page, :Pages]

Instance Method Summary collapse

Constructor Details

#initializeObjectCache

Returns a new instance of ObjectCache.



16
17
18
# File 'lib/pdf/reader/object_cache.rb', line 16

def initialize
  @objects = {}
end

Instance Method Details

#[](key) ⇒ Object



20
21
22
# File 'lib/pdf/reader/object_cache.rb', line 20

def [](key)
  @objects[key]
end

#[]=(key, value) ⇒ Object



24
25
26
# File 'lib/pdf/reader/object_cache.rb', line 24

def []=(key, value)
  @objects[key] = value if cacheable?(value)
end

#each(&block) ⇒ Object Also known as: each_pair



32
33
34
# File 'lib/pdf/reader/object_cache.rb', line 32

def each(&block)
  @objects.each(&block)
end

#each_key(&block) ⇒ Object



37
38
39
# File 'lib/pdf/reader/object_cache.rb', line 37

def each_key(&block)
  @objects.each_key(&block)
end

#each_value(&block) ⇒ Object



41
42
43
# File 'lib/pdf/reader/object_cache.rb', line 41

def each_value(&block)
  @objects.each_value(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/pdf/reader/object_cache.rb', line 50

def empty?
  @objects.empty?
end

#fetch(key, local_default = nil) ⇒ Object



28
29
30
# File 'lib/pdf/reader/object_cache.rb', line 28

def fetch(key, local_default = nil)
  @objects.fetch(key, local_default)
end

#has_key?(key) ⇒ Boolean Also known as: include?, key?, member?

Returns:

  • (Boolean)


54
55
56
# File 'lib/pdf/reader/object_cache.rb', line 54

def has_key?(key)
  @objects.has_key?(key)
end

#has_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/pdf/reader/object_cache.rb', line 61

def has_value?(value)
  @objects.has_value?(value)
end

#keysObject



69
70
71
# File 'lib/pdf/reader/object_cache.rb', line 69

def keys
  @objects.keys
end

#sizeObject Also known as: length



45
46
47
# File 'lib/pdf/reader/object_cache.rb', line 45

def size
  @objects.size
end

#to_sObject



65
66
67
# File 'lib/pdf/reader/object_cache.rb', line 65

def to_s
  "<PDF::Reader::ObjectCache size: #{self.size}>"
end

#valuesObject



73
74
75
# File 'lib/pdf/reader/object_cache.rb', line 73

def values
  @objects.values
end