Class: Fluent::Plugin::LdapClient::CacheTTL
- Inherits:
-
Object
- Object
- Fluent::Plugin::LdapClient::CacheTTL
- Defined in:
- lib/fluent/plugin/ldap_client/cache_ttl.rb
Constant Summary collapse
- CACHE_SIZE =
1000- TTL_POSITIVE =
14 * 3600
- TTL_NEGATIVE =
3600
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#ttl_negative ⇒ Object
readonly
Returns the value of attribute ttl_negative.
-
#ttl_positive ⇒ Object
readonly
Returns the value of attribute ttl_positive.
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(size: CACHE_SIZE, ttl_positive: TTL_POSITIVE, ttl_negative: TTL_NEGATIVE) ⇒ CacheTTL
constructor
A new instance of CacheTTL.
Constructor Details
#initialize(size: CACHE_SIZE, ttl_positive: TTL_POSITIVE, ttl_negative: TTL_NEGATIVE) ⇒ CacheTTL
Returns a new instance of CacheTTL.
13 14 15 16 17 18 19 20 |
# File 'lib/fluent/plugin/ldap_client/cache_ttl.rb', line 13 def initialize(size: CACHE_SIZE, ttl_positive: TTL_POSITIVE, ttl_negative: TTL_NEGATIVE) @size = size @ttl_positive = ttl_positive @ttl_negative = ttl_negative @cache = {} @access_order = [] end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
11 12 13 |
# File 'lib/fluent/plugin/ldap_client/cache_ttl.rb', line 11 def size @size end |
#ttl_negative ⇒ Object (readonly)
Returns the value of attribute ttl_negative.
11 12 13 |
# File 'lib/fluent/plugin/ldap_client/cache_ttl.rb', line 11 def ttl_negative @ttl_negative end |
#ttl_positive ⇒ Object (readonly)
Returns the value of attribute ttl_positive.
11 12 13 |
# File 'lib/fluent/plugin/ldap_client/cache_ttl.rb', line 11 def ttl_positive @ttl_positive end |
Instance Method Details
#get(key) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fluent/plugin/ldap_client/cache_ttl.rb', line 22 def get(key) cleanup_expired_entries if @cache.key?(key) && !expired?(@cache[key]) refresh_access_order(key) return @cache[key][:value] end result = yield key store(key, result) result end |