Class: GH::Cache
Overview
Public: This class caches responses.
Defined Under Namespace
Classes: SimpleCache
Instance Attribute Summary collapse
-
#cache ⇒ Object
Public: Get/set cache to use.
Attributes inherited from Wrapper
Instance Method Summary collapse
-
#[](key) ⇒ Object
Public: Retrieves resources from Github and caches response for future access.
-
#reset ⇒ Object
Public: …
-
#setup ⇒ Object
Internal: Initializes a new Cache instance.
Methods inherited from Wrapper
[], #frontend, #frontend=, #initialize, #inspect, #load, #prefixed, wraps
Constructor Details
This class inherits a constructor from GH::Wrapper
Instance Attribute Details
#cache ⇒ Object
Public: Get/set cache to use. Compatible with Rails/ActiveSupport cache.
8 9 10 |
# File 'lib/gh/cache.rb', line 8 def cache @cache end |
Instance Method Details
#[](key) ⇒ Object
Public: Retrieves resources from Github and caches response for future access.
Examples
Github::Cache.new['users/rkh'] # => { ... }
Returns the Response.
53 54 55 |
# File 'lib/gh/cache.rb', line 53 def [](key) cache.fetch(prefixed(key)) { super } end |
#reset ⇒ Object
Public: …
41 42 43 44 |
# File 'lib/gh/cache.rb', line 41 def reset super clear_partial or clear_all end |
#setup ⇒ Object
Internal: Initializes a new Cache instance.
33 34 35 36 37 38 |
# File 'lib/gh/cache.rb', line 33 def setup(*) self.cache ||= Rails.cache if defined? Rails.cache and defined? RAILS_CACHE self.cache ||= ActiveSupport::Cache.lookup_store if defined? ActiveSupport::Cache.lookup_store self.cache ||= SimpleCache.new super end |