class PokeAPI::Cache
- PokeAPI::Cache
- Reference
- Object
Defined in:
pokeapi/cache.crConstructors
-
.new(time_cached : Time::Span = 30.minutes)
Creates a new Cache.
Instance Method Summary
-
#add(key : String, data : String)
Adds data to the cache.
-
#clear : Bool
Clears the cache.
-
#disable
Disables the cache.
-
#empty? : Bool
Returns
true
when the cache is empty. -
#enable
Enables the cache.
-
#get(key : String) : NamedTuple(data: String, cachedTime: Time)
Retrieves data from the cache.
-
#has_key?(key : String) : Bool
Checks if cache contains key.
-
#is_enabled? : Bool
Returns
true
if the cache is enabled, otherwisefalse
. -
#set_cache_time(cache_time : Time::Span)
Sets the time that data is cached to cache_time.
Constructor Detail
Instance Method Detail
def clear : Bool
#
Clears the cache.
true
is returned if the cache was cleared successfully, otherwise false
.
def has_key?(key : String) : Bool
#
Checks if cache contains key.
Returns true
is key is in cache and the value has not been
cached for more than time_cached.
false
is returned if key doesn't exist in the cache or if
the cached data is out-dated.
Out-dated data gets deleted before false
is returned.