Class: Hyrax::CachingIiifManifestBuilder

Inherits:
ManifestBuilderService show all
Defined in:
app/services/hyrax/caching_iiif_manifest_builder.rb

Overview

constructs IIIF Manifests and holds them in the Rails cache, this approach avoids long manifest build times for some kinds of requests, at the cost of introducing cache invalidation issues.

Constant Summary collapse

KEY_PREFIX =
'iiif-cache-v1'

Instance Attribute Summary collapse

Attributes inherited from ManifestBuilderService

#manifest_factory

Instance Method Summary collapse

Methods inherited from ManifestBuilderService

manifest_for

Constructor Details

#initialize(iiif_manifest_factory: ::IIIFManifest::ManifestFactory, expires_in: Hyrax.config.iiif_manifest_cache_duration) ⇒ CachingIiifManifestBuilder

Returns a new instance of CachingIiifManifestBuilder.

Parameters:

  • iiif_manifest_factory (Class) (defaults to: ::IIIFManifest::ManifestFactory)

    a class that initializes with presenter object and returns an object that responds to `#to_h`

  • expires_in (Integer) (defaults to: Hyrax.config.iiif_manifest_cache_duration)

    the number of seconds until the cache expires

See Also:


20
21
22
23
24
# File 'app/services/hyrax/caching_iiif_manifest_builder.rb', line 20

def initialize(iiif_manifest_factory: ::IIIFManifest::ManifestFactory, expires_in: Hyrax.config.iiif_manifest_cache_duration)
  self.expires_in = expires_in

  super(iiif_manifest_factory: iiif_manifest_factory)
end

Instance Attribute Details

#expires_inObject

Returns the value of attribute expires_in


11
12
13
# File 'app/services/hyrax/caching_iiif_manifest_builder.rb', line 11

def expires_in
  @expires_in
end

Instance Method Details

#manifest_for(presenter:) ⇒ Object

See Also:

  • ManifestBuilderService#as_json

28
29
30
31
32
# File 'app/services/hyrax/caching_iiif_manifest_builder.rb', line 28

def manifest_for(presenter:)
  Rails.cache.fetch(manifest_cache_key(presenter: presenter), expires_in: expires_in) do
    super
  end
end