Module: Parliament::OpenSearch::DescriptionCache

Defined in:
lib/parliament/open_search/description_cache.rb

Overview

A module used to download, cache and serve description files for our OpenSearch requests.

Since:

  • 0.1

Constant Summary collapse

DESCRIPTION_CACHE_TIME =

10 minutes

Since:

  • 0.1

600

Class Method Summary collapse

Class Method Details

.delete(uri) ⇒ nil|Hash

Given a uri, remove the description from our store.

Parameters:

  • uri (String)

    the uri of our description

Returns:

  • (nil|Hash)

    returns nil if the description was not in the store, or a Hash representing the deleted description’s entry

Since:

  • 0.1



33
34
35
36
37
# File 'lib/parliament/open_search/description_cache.rb', line 33

def delete(uri)
  store

  @store.delete(uri)
end

.fetch(uri, request_id = nil) ⇒ String

Given a description uri, either download the file or serve it from our cache

Parameters:

  • uri (String)

    the uri of our description file

  • request_id (optional, String) (defaults to: nil)

    a Request-Id base value

Returns:

  • (String)

    our description file

Since:

  • 0.1



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/parliament/open_search/description_cache.rb', line 14

def fetch(uri, request_id = nil)
  store

  if cache_valid?(store[uri])
    templates = @store[uri][:templates]
  else
    templates = download_description_templates(uri, request_id)

    @store[uri] = { timestamp: Time.now, templates: templates }
  end

  templates
end

.storeHash

Returns a copy of our description store

Returns:

  • (Hash)

    returns our description store

Since:

  • 0.1



42
43
44
# File 'lib/parliament/open_search/description_cache.rb', line 42

def store
  @store ||= {}
end