-
-
Notifications
You must be signed in to change notification settings - Fork 25
LeagueAPI: Call caching
Version v3.0.0-rc.1
This feature can prevent unnecessary calls to API within short timespan by temporarily saving fetched data from API and using them as the result data.
In order to enable this feature, you have to set LeagueAPI::SET_CACHE_CALLS
to true
.
You should also provide LeagueAPI::SET_CACHE_CALLS_LENGTH
option or else default time interval of 60 seconds
will be used.
Settings key | Data type | Info / Possible values |
---|---|---|
LeagueAPI::SET_CACHE_CALLS |
bool |
true , false
|
LeagueAPI::SET_CACHE_CALLS_LENGTH |
int |array
|
see example below |
LeagueAPI::SET_CACHE_CALLS_LENGTH
can either be int
only - in that case, this time interval will be set onto every resource-endpoint
or it can be an array
specifying the time interval separately for each resource
- only specified resources will be cached in this case, others will remain uncached.
Variable | Data type | Info / Possible values |
---|---|---|
$RESOURCEx |
string |
LeagueAPI::RESOURCE_CHAMPION , LeagueAPI::RESOURCE_CHAMPIONMASTERY , LeagueAPI::RESOURCE_LEAGUE , LeagueAPI::RESOURCE_STATICDATA , LeagueAPI::RESOURCE_STATUS , LeagueAPI::RESOURCE_MASTERIES , LeagueAPI::RESOURCE_MATCH , LeagueAPI::RESOURCE_RUNES , LeagueAPI::RESOURCE_SPECTATOR , LeagueAPI::RESOURCE_SUMMONER , LeagueAPI::RESOURCE_TOURNAMENT , LeagueAPI::RESOURCE_TOURNAMENT_STUB
|
$TIME_LIMITx |
int |
time limit in seconds |
$callsLength = [
$RESOURCE1 => $TIME_LIMIT1,
$RESOURCE2 => $TIME_LIMIT2,
$RESOURCE3 => $TIME_LIMIT3,
];
Caching calls on all resources
for $TIME_LIMIT0
seconds:
use RiotAPI\LeagueAPI\LeagueAPI;
$api = new LeagueAPI([
// ...
LeagueAPI::SET_CACHE_CALLS => true,
LeagueAPI::SET_CACHE_CALLS_LENGTH => $TIME_LIMIT0,
// ...
]);
Caching calls only on LeagueAPI::RESOURCE_STATICDATA
resource
for $TIME_LIMIT1
and LeagueAPI::RESOURCE_SUMMONER
resource
for $TIME_LIMIT2
seconds (calls on different
resources
will not be cached at all):
use RiotAPI\LeagueAPI\LeagueAPI;
$api = new LeagueAPI([
// ...
LeagueAPI::SET_CACHE_CALLS => true,
LeagueAPI::SET_CACHE_CALLS_LENGTH => [
LeagueAPI::RESOURCE_STATICDATA => $TIME_LIMIT1,
LeagueAPI::RESOURCE_SUMMONER => $TIME_LIMIT2,
],
// ...
]);
If LeagueAPI::SET_CACHE_CALLS_LENGTH
will be left unset, library will use these default values:
Resource | Cached time |
---|---|
LeagueAPI::RESOURCE_CHAMPION |
10 minutes |
LeagueAPI::RESOURCE_CHAMPIONMASTERY |
1 hour |
LeagueAPI::RESOURCE_LEAGUE |
10 minutes |
LeagueAPI::RESOURCE_STATICDATA |
whole patch |
LeagueAPI::RESOURCE_STATUS |
1 minute |
LeagueAPI::RESOURCE_MATCH |
uncached |
LeagueAPI::RESOURCE_SPECTATOR |
uncached |
LeagueAPI::RESOURCE_SUMMONER |
1 hour |
LeagueAPI::RESOURCE_TOURNAMENT |
uncached |
LeagueAPI::RESOURCE_TOURNAMENT_STUB |
uncached |