Class: Warden::GitHub::MembershipCache
- Inherits:
-
Object
- Object
- Warden::GitHub::MembershipCache
- Defined in:
- lib/warden/github/membership_cache.rb
Overview
A hash subclass that acts as a cache for organization and team membership states. Only membership states that are true are cached. These are invalidated after a certain time.
Constant Summary collapse
- CACHE_TIMEOUT =
60 * 5
Instance Method Summary collapse
-
#fetch_membership(type, id) ⇒ Object
Fetches a membership status by type and id (e.g. ‘org’, ‘my_company’) from cache.
-
#initialize(data) ⇒ MembershipCache
constructor
A new instance of MembershipCache.
Constructor Details
#initialize(data) ⇒ MembershipCache
Returns a new instance of MembershipCache.
9 10 11 |
# File 'lib/warden/github/membership_cache.rb', line 9 def initialize(data) @data = data end |
Instance Method Details
#fetch_membership(type, id) ⇒ Object
Fetches a membership status by type and id (e.g. ‘org’, ‘my_company’) from cache. If no cached value is present or if the cached value expired, the block will be invoked and the return value, if true, cached for e certain time.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/warden/github/membership_cache.rb', line 17 def fetch_membership(type, id) type = type.to_s id = id.to_s if cached_membership_valid?(type, id) true elsif block_given? && yield cache_membership(type, id) true else false end end |