Skip to content

Commit 775dabc

Browse files
authored
Added support for namespaced cache (#46)
* Added support for namespaced cache * Applied fixes from StyleCI (#47) * Added change log
1 parent e97ee76 commit 775dabc

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
44

55
## UNRELEASED
66

7+
## 0.3.5
8+
79
### Added
810

911
* `ConnectException` that is thrown when you fail to connect to Redis
12+
* Support for using the `NamespacedCachePool`
1013

1114
### Fixed
1215

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"php": "^5.5 || ^7.0",
2222
"symfony/framework-bundle": "^2.7 || ^3.0",
2323
"symfony/options-resolver": "^2.7 || ^3.0",
24-
"psr/cache": "^1.0"
24+
"psr/cache": "^1.0",
25+
"cache/namespaced-cache": "^0.1"
2526
},
2627
"require-dev": {
2728
"phpunit/phpunit": "5.0.* || ^4.0",

src/Factory/MemcachedFactory.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Cache\Adapter\Memcached\MemcachedCachePool;
1515
use Cache\AdapterBundle\ProviderHelper\Memcached;
16+
use Cache\Namespaced\NamespacedCachePool;
1617
use Symfony\Component\OptionsResolver\OptionsResolver;
1718

1819
/**
@@ -32,7 +33,13 @@ public function getAdapter(array $config)
3233
$client = new Memcached($config['persistent_id']);
3334
$client->addServer($config['host'], $config['port']);
3435

35-
return new MemcachedCachePool($client);
36+
$pool = new MemcachedCachePool($client);
37+
38+
if (null !== $config['pool_namespace']) {
39+
$pool = new NamespacedCachePool($pool, $config['pool_namespace']);
40+
}
41+
42+
return $pool;
3643
}
3744

3845
/**
@@ -41,13 +48,15 @@ public function getAdapter(array $config)
4148
protected static function configureOptionResolver(OptionsResolver $resolver)
4249
{
4350
$resolver->setDefaults([
44-
'persistent_id' => null,
45-
'host' => '127.0.0.1',
46-
'port' => 11211,
51+
'persistent_id' => null,
52+
'host' => '127.0.0.1',
53+
'port' => 11211,
54+
'pool_namespace' => null,
4755
]);
4856

4957
$resolver->setAllowedTypes('persistent_id', ['string', 'null']);
5058
$resolver->setAllowedTypes('host', ['string']);
5159
$resolver->setAllowedTypes('port', ['string', 'int']);
60+
$resolver->setAllowedTypes('pool_namespace', ['string', 'null']);
5261
}
5362
}

src/Factory/PredisFactory.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Cache\AdapterBundle\Factory;
1313

1414
use Cache\Adapter\Predis\PredisCachePool;
15+
use Cache\Namespaced\NamespacedCachePool;
1516
use Predis\Client;
1617
use Symfony\Component\OptionsResolver\OptionsResolver;
1718

@@ -43,7 +44,13 @@ public function getAdapter(array $config)
4344
$client = new Client($dsn->getDsn());
4445
}
4546

46-
return new PredisCachePool($client);
47+
$pool = new PredisCachePool($client);
48+
49+
if (null !== $config['pool_namespace']) {
50+
$pool = new NamespacedCachePool($pool, $config['pool_namespace']);
51+
}
52+
53+
return $pool;
4754
}
4855

4956
/**
@@ -55,14 +62,16 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
5562

5663
$resolver->setDefaults(
5764
[
58-
'host' => '127.0.0.1',
59-
'port' => '6379',
60-
'scheme' => 'tcp',
65+
'host' => '127.0.0.1',
66+
'port' => '6379',
67+
'scheme' => 'tcp',
68+
'pool_namespace' => null,
6169
]
6270
);
6371

6472
$resolver->setAllowedTypes('host', ['string']);
6573
$resolver->setAllowedTypes('port', ['string', 'int']);
6674
$resolver->setAllowedTypes('scheme', ['string']);
75+
$resolver->setAllowedTypes('pool_namespace', ['string', 'null']);
6776
}
6877
}

src/Factory/RedisFactory.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Cache\Adapter\Redis\RedisCachePool;
1515
use Cache\AdapterBundle\Exception\ConnectException;
16+
use Cache\Namespaced\NamespacedCachePool;
1617
use Symfony\Component\OptionsResolver\OptionsResolver;
1718

1819
/**
@@ -55,7 +56,13 @@ public function getAdapter(array $config)
5556
}
5657
}
5758

58-
return new RedisCachePool($client);
59+
$pool = new RedisCachePool($client);
60+
61+
if (null !== $config['pool_namespace']) {
62+
$pool = new NamespacedCachePool($pool, $config['pool_namespace']);
63+
}
64+
65+
return $pool;
5966
}
6067

6168
/**
@@ -67,12 +74,14 @@ protected static function configureOptionResolver(OptionsResolver $resolver)
6774

6875
$resolver->setDefaults(
6976
[
70-
'host' => '127.0.0.1',
71-
'port' => '6379',
77+
'host' => '127.0.0.1',
78+
'port' => '6379',
79+
'pool_namespace' => null,
7280
]
7381
);
7482

7583
$resolver->setAllowedTypes('host', ['string']);
7684
$resolver->setAllowedTypes('port', ['string', 'int']);
85+
$resolver->setAllowedTypes('pool_namespace', ['string', 'null']);
7786
}
7887
}

0 commit comments

Comments
 (0)