Skip to content

Commit 29ccdee

Browse files
committed
Adding caching capabilities implemented in php-tmdb-api
1 parent bea68aa commit 29ccdee

File tree

6 files changed

+52
-14
lines changed

6 files changed

+52
-14
lines changed

DependencyInjection/Configuration.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public function getConfigTreeBuilder()
2323
$rootNode
2424
->children()
2525
->scalarNode('api_key')->end()
26+
->arrayNode('cache')
27+
->children()
28+
->scalarNode('enabled')->end()
29+
->scalarNode('path')->end()
30+
->end()
31+
->end()
2632
->end()
2733
;
2834

DependencyInjection/WtfzTmdbExtension.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ public function load(array $configs, ContainerBuilder $container)
3131
);
3232
}
3333

34-
$container->setParameter(
35-
'wtfz_tmdb.api_key',
36-
$config['api_key']
37-
);
34+
$container->setParameter('wtfz_tmdb.api_key', $config['api_key']);
35+
36+
if (array_key_exists('cache', $config)) {
37+
$cacheEnabled = array_key_exists('enabled', $config['cache']) && $config['cache']['enabled'];
38+
$cachePath = array_key_exists('path', $config['cache']) ? $config['cache']['path'] : null;
39+
40+
$container->setParameter('wtfz_tmdb.cache.enabled', $cacheEnabled);
41+
$container->setParameter('wtfz_tmdb.cache.path', $cachePath);
42+
}
3843
}
3944
}

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ wtfz_tmdb:
1919
2020
That's all! Fire away!
2121
22+
** Want to make use of default caching? **
23+
24+
This caching system will adhere to the TMDB API max-age values, if you have different needs like long TTL's
25+
you'd have to make your own implementation. We would be happy to intergrate more options, so please contribute.
26+
27+
```yaml
28+
wtfz_tmdb:
29+
api_key: YOUR_API_KEY_HERE
30+
cache:
31+
enabled: true
32+
path: "/tmp/php-tmdb-api"
33+
```
34+
2235
__There will be adult and language filters coming in a later stage, so later on the configuration will look like:__
2336
2437
```yaml

Resources/config/tmdb.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8+
<!-- Options parameters -->
89
<parameter key="wtfz_tmdb.api_key" />
10+
<parameter key="wtfz_tmdb.cache.enabled" />
11+
<parameter key="wtfz_tmdb.cache.path" />
912

1013
<!-- Main classes -->
11-
<parameter key="wtfz_tmdb.api_token.class">Tmdb\ApiToken</parameter>
1214
<parameter key="wtfz_tmdb.client.class">Tmdb\Client</parameter>
15+
<parameter key="wtfz_tmdb.api_token.class">Tmdb\ApiToken</parameter>
16+
<parameter key="wtfz_tmdb.request_token.class">Tmdb\RequestToken</parameter>
17+
<parameter key="wtfz_tmdb.session_token.class">Tmdb\SessionToken</parameter>
1318

1419
<!-- Repository classes -->
20+
<parameter key="wtfz_tmdb.authentication_repository.class">Tmdb\Repository\AuthenticationRepository</parameter>
21+
<parameter key="wtfz_tmdb.account_repository.class">Tmdb\Repository\AccountRepository</parameter>
1522
<parameter key="wtfz_tmdb.certification_repository.class">Tmdb\Repository\CertificationRepository</parameter>
1623
<parameter key="wtfz_tmdb.changes_repository.class">Tmdb\Repository\ChangesRepository</parameter>
1724
<parameter key="wtfz_tmdb.collection_repository.class">Tmdb\Repository\CollectionRepository</parameter>
@@ -37,6 +44,10 @@
3744
<services>
3845
<service id="wtfz_tmdb.client" class="%wtfz_tmdb.client.class%">
3946
<argument type="service" id="wtfz_tmdb.api_token" />
47+
<call method="setCaching">
48+
<argument>%wtfz_tmdb.cache.enabled%</argument>
49+
<argument>%wtfz_tmdb.cache.path%</argument>
50+
</call>
4051
</service>
4152

4253
<service id="wtfz_tmdb.api_token" class="%wtfz_tmdb.api_token.class%">

Twig/WtfzTmdbExtension.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* For the full copyright and license information, please view the LICENSE
66
* file that was distributed with this source code.
7-
*
7+
*
88
* @package Wrike
99
* @author Michael Roterman <michael@b-found.nl>
1010
* @copyright (c) 2013, B-Found Internet Marketing & Services
@@ -13,13 +13,13 @@
1313

1414
namespace Wtfz\TmdbBundle\Twig;
1515

16-
1716
use Tmdb\Client;
1817
use Tmdb\Helper\ImageHelper;
1918
use Tmdb\Model\Image;
2019
use Tmdb\Repository\ConfigurationRepository;
2120

22-
class WtfzTmdbExtension extends \Twig_Extension {
21+
class WtfzTmdbExtension extends \Twig_Extension
22+
{
2323
private $helper;
2424

2525
private $client;
@@ -60,12 +60,13 @@ public function getName()
6060
}
6161

6262
/**
63-
* @param null $client
63+
* @param null $client
6464
* @return $this
6565
*/
6666
public function setClient($client)
6767
{
6868
$this->client = $client;
69+
6970
return $this;
7071
}
7172

@@ -78,12 +79,13 @@ public function getClient()
7879
}
7980

8081
/**
81-
* @param mixed $configuration
82+
* @param mixed $configuration
8283
* @return $this
8384
*/
8485
public function setConfiguration($configuration)
8586
{
8687
$this->configuration = $configuration;
88+
8789
return $this;
8890
}
8991

@@ -96,12 +98,13 @@ public function getConfiguration()
9698
}
9799

98100
/**
99-
* @param \Wtfz\TmdbBundle\Twig\Tmdb\Helper\ImageHelper $helper
101+
* @param \Wtfz\TmdbBundle\Twig\Tmdb\Helper\ImageHelper $helper
100102
* @return $this
101103
*/
102104
public function setHelper($helper)
103105
{
104106
$this->helper = $helper;
107+
105108
return $this;
106109
}
107110

@@ -113,5 +116,4 @@ public function getHelper()
113116
return $this->helper;
114117
}
115118

116-
117-
}
119+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
}
1414
],
1515
"require": {
16-
"wtfzdotnet/php-tmdb-api": "*"
16+
"wtfzdotnet/php-tmdb-api": "*",
17+
"doctrine/cache": ">=1.3.0"
1718
},
1819
"autoload": {
1920
"psr-0": { "Wtfz\\TmdbBundle": "" }

0 commit comments

Comments
 (0)