Skip to content

Commit

Permalink
order caching examples and add internal links. refs #19
Browse files Browse the repository at this point in the history
  • Loading branch information
nealio82 committed Mar 31, 2016
1 parent bb15907 commit 8bb8980
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions documentation/Usage/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Caching API responses can greatly speed up certain areas of your application. This SDK ships with a number of cache options which all use the Doctrine Cache drivers. Included are:

- Filesystem cache
- APC*
- xCache*
- Memcache*
- Memcached*
- [Filesystem cache](#filesystem)
- [APC](#apc)*
- [xCache](#xcache)*
- [Memcache](#memcache)*
- [Memcached](#memcached)*

*Note: To use the APC, xCache, Memcache, or Memcached caches you will need the relevant PHP extension installed and enabled in your PHP environment.

Expand All @@ -24,7 +24,7 @@ Additionally, the `DoctrineFilesystemCache` class provided with this SDK require

The `CachingApiClient` only caches read requests. It does not cache creation or updating of API objects.

### Using `DoctrineFilesystemCache`
#### Using `DoctrineFilesystemCache` <a name="filesystem"></a>

```php
use MediaMath\TerminalOneAPI\CachingApiClient;
Expand All @@ -47,29 +47,41 @@ var_dump($vertical->data());
```


### Using `DoctrineMemcachedCache`
#### Using `DoctrineAPCCache` <a name="apc"></a>

Note that on Debian / Ubuntu systems the `php5-apc` extension may have been renamed to `php5-apcu`. The `DoctrineAPCCache` will work regardless of which is installed.

```php
use MediaMath\TerminalOneAPI\CachingApiClient;
use MediaMath\TerminalOneAPI\Decoder\JSONResponseDecoder;
use MediaMath\TerminalOneAPI\Cache\DoctrineMemcachedCache;
use MediaMath\TerminalOneAPI\Cache\DoctrineAPCCache;
use MediaMath\TerminalOneAPI\Cache\TimePeriod;

/*
* Optionally specify a pool name for memcached,
* if none is provided the default 't1_api' is used
*/
$pool_name = 'acme_t1_api_pool';
$cached_client = new CachingApiClient($transport, new DoctrineAPCCache(TimePeriod::minutes(3));

$cached_client = new CachingApiClient($transport, new DoctrineMemcachedCache(TimePeriod::minutes(3), $pool_name));
$vertical = $cached_client->read(new Management\Vertical(), new JSONResponseDecoder());

var_dump($vertical->data());
```


#### Using `DoctrineXCacheCache` <a name="xcache"></a>

```php
use MediaMath\TerminalOneAPI\CachingApiClient;
use MediaMath\TerminalOneAPI\Decoder\JSONResponseDecoder;
use MediaMath\TerminalOneAPI\Cache\DoctrineXCacheCache;
use MediaMath\TerminalOneAPI\Cache\TimePeriod;

$cached_client = new CachingApiClient($transport, new DoctrineXCacheCache(TimePeriod::minutes(3));

$vertical = $cached_client->read(new Management\Vertical(), new JSONResponseDecoder());

var_dump($vertical->data());
```


### Using `DoctrineMemcacheCache`
#### Using `DoctrineMemcacheCache` <a name="memcache"></a>

```php
use MediaMath\TerminalOneAPI\CachingApiClient;
Expand All @@ -95,33 +107,21 @@ var_dump($vertical->data());
```


### Using `DoctrineXCacheCache`
#### Using `DoctrineMemcachedCache` <a name="memcached"></a>

```php
use MediaMath\TerminalOneAPI\CachingApiClient;
use MediaMath\TerminalOneAPI\Decoder\JSONResponseDecoder;
use MediaMath\TerminalOneAPI\Cache\DoctrineXCacheCache;
use MediaMath\TerminalOneAPI\Cache\DoctrineMemcachedCache;
use MediaMath\TerminalOneAPI\Cache\TimePeriod;

$cached_client = new CachingApiClient($transport, new DoctrineXCacheCache(TimePeriod::minutes(3));

$vertical = $cached_client->read(new Management\Vertical(), new JSONResponseDecoder());

var_dump($vertical->data());
```


### Using `DoctrineAPCCache`

Note that on Debian / Ubuntu systems the `php5-apc` extension may have been renamed to `php5-apcu`. The `DoctrineAPCCache` will work regardless of which is installed.

```php
use MediaMath\TerminalOneAPI\CachingApiClient;
use MediaMath\TerminalOneAPI\Decoder\JSONResponseDecoder;
use MediaMath\TerminalOneAPI\Cache\DoctrineAPCCache;
use MediaMath\TerminalOneAPI\Cache\TimePeriod;
/*
* Optionally specify a pool name for memcached,
* if none is provided the default 't1_api' is used
*/
$pool_name = 'acme_t1_api_pool';

$cached_client = new CachingApiClient($transport, new DoctrineAPCCache(TimePeriod::minutes(3));
$cached_client = new CachingApiClient($transport, new DoctrineMemcachedCache(TimePeriod::minutes(3), $pool_name));

$vertical = $cached_client->read(new Management\Vertical(), new JSONResponseDecoder());

Expand Down

0 comments on commit 8bb8980

Please sign in to comment.