h-space / api-cacher-bundle
Api requests smart cacher for perfomance optimization
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/h-space/api-cacher-bundle
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2026-01-07 14:22:22 UTC
README
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.
Installation
Composer:
"require": { "h-space/api-cacher-bundle": "dev-master" }
$ composer install
Usage
Include the library:
use HSpace\Bundle\ApiCacherBundle\Library\ApiCacher;
Initialize class:
$cacher = new ApiCacher();
Single request:
$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:
$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
To erase all cache files include
eraseCache=true$_GET parameter in your request.
Enable Auto Refreshing Of Cache Files
Import the resource on your app/config/routing.yml
_hspace:
resource: "@HSpaceApiCacherBundle/Resources/config/routing.yml"
Call the function at your end of your class/controller
$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);
Version
1.0.0
License
MIT
Free Software, Hell Yeah!