2017 © Pedro Peláez
 

library api-cacher-bundle

Api requests smart cacher for perfomance optimization

image

h-space/api-cacher-bundle

Api requests smart cacher for perfomance optimization

  • Friday, March 27, 2015
  • by nikos_90
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ApiCacher Bundle

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)

Installation

Composer:, (*2)

"require": {
        "h-space/api-cacher-bundle": "dev-master"
    }
$ composer install

Usage

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)

Enable Auto Refreshing Of Cache Files

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)

Version

1.0.0, (*12)

License

MIT, (*13)

Free Software, Hell Yeah!, (*14)

The Versions

27/03 2015

dev-master

9999999-dev

Api requests smart cacher for perfomance optimization

  Sources   Download

MIT

The Development Requires

by Nikos Aggelakis

apicacher apicacherbundle