dev-master
9999999-devApi requests smart cacher for perfomance optimization
MIT
The Development Requires
by Nikos Aggelakis
apicacher apicacherbundle
Wallogit.com
2017 © Pedro Peláez
Api requests smart cacher for perfomance optimization
ApiCacher is a symfony2 caching system for data provided by API endpoints. It is used for optimising the performance of a website that uses external API services for data., (*1)
Composer:, (*2)
"require": {
"h-space/api-cacher-bundle": "dev-master"
}
$ composer install
Include the library:, (*3)
use HSpace\Bundle\ApiCacherBundle\Library\ApiCacher;
Initialize class:, (*4)
$cacher = new ApiCacher();
Single request:, (*5)
$url = 'https://example.com/api/endpoint?api_key=YOUR_API_KEY';
$fields = null; // if post request, fields is an array with post data else null
$json_decode = true;
$rebuild_cache = true; // rebuild cache at the the end of the proccess, more details below
$response = $cacher->request($url,$fields,$json_decode,$rebuild_cache);
Multi Requests:, (*6)
$url_one = 'https://example.com/api/endpoint?api_key=YOUR_API_KEY';
$url_two = 'https://example.com/api/endpoint_two?api_key=YOUR_API_KEY';
$fields = null; // if post request, fields is an array with post data else null
$json_decode = true;
$rebuild_cache = true; // rebuild cache at the the end of the proccess, more details below
$cacher->request_multi($url_one,$fields,$json_decode,$rebuild_cache);
$cacher->request_multi($url_two,$fields,$json_decode,$rebuild_cache);
$cacher->execute($json_decode);
$responses = $cacher->multi_output();
//Accessing the responses
$url_one_response = $responses[$url_one];
$url_two_response = $responses[$url_two];
Erase Cache Listener, (*7)
To erase all cache files include
eraseCache=true$_GET parameter in your request., (*8)Example: http://yoursite.com/homepage?eraseCache=true, (*9)
Import the resource on your app/config/routing.yml
sh
_hspace:
resource: "@HSpaceApiCacherBundle/Resources/config/routing.yml"
Call the function at your end of your class/controller
```sh
$route = $this->generateUrl('hspace_reload_cache',array(), true); // for controller usage, you have to generate the url if you are outside of controller
$cacher->teardown($route);, (*10)
```, (*11)
1.0.0, (*12)
MIT, (*13)
Free Software, Hell Yeah!, (*14)
Api requests smart cacher for perfomance optimization
MIT
apicacher apicacherbundle