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



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

def delete(uri)
  store

  @store.delete(uri)
end

.fetch(uri) ⇒ String

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

Parameters:

  • uri (String)

    the uri of our description file

Returns:

  • (String)

    our description file

Since:

  • 0.1



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

def fetch(uri)
  store

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

    @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



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

def store
  @store ||= {}
end