Created
July 5, 2012 08:02
-
-
Save sfalquier/3052181 to your computer and use it in GitHub Desktop.
Memcached in Symfony2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//file app/config/parameters.ini | |
[parameters] | |
memcached_host = 127.0.0.1 | |
memcached_port = 11211 | |
memcached_key_root = mykey | |
memcached_object_ttl = 60 | |
//file src/MyApp/MyBundle/Resources/config/services.yml | |
parameters: | |
memcached.servers: | |
- { host: %memcached_host%, port: %memcached_port% } | |
services: | |
memcached: | |
class: Memcached | |
calls: | |
- [ addServers, [ %memcached.servers% ]] | |
//file src/MyApp/MyBundle/Controller/MyController.php | |
$memcached = $this->get('memcached'); | |
$memcachedObjectTtl = $this->container->getParameter('memcached_info_ttl'); | |
$memcachedKeyRoot = $this->container->getParameter('memcached_key_root'); | |
$object = $memcached->get($memcachedKeyRoot.$objectKey); | |
if(!$object) { | |
$object = $this->getObject($objectKey);//TODO coder la méthode getObject | |
$memcached->set($memcachedKeyRoot.$objectKey,$object,$memcachedObjectTtl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment