Clone this wiki locally
In order to decrease requests made to the server, it is possible to tell a neo4jphp client to cache the results of entity look-ups.
Three caching plugins come with neo4jphp:
- Null - no caching is performed
- Variable - entities are cached for the length of the PHP process/request
- Memcached - entities are cached using PHP's Memcached extension
It is possible to define your own caching plugin by implementing the
The following client methods interact with the cache:
Client::deleteRelationship()- Removes the entity by id from the cache.
Client::getRelationship()- Looks up the entity by id in the cache and returns it. Multiple calls return the same object.
Client::loadRelationship()- Looks up the entity by id in the cache, and loads its properties into the supplied entity.
Client::saveRelationship()- Stores the entity by id in the cache.
Setting up the Cache
Caching is enabled by instantiating a cache plugin and then calling
Client::setCache(). The following code sets up caching using the local variable cache plugin:
$plugin = new Everyman\Neo4j\Cache\Variable(); $client->getEntityCache()->setCache($plugin);
This example uses the Memcached plugin:
$memcached = new Memcached(); $memcached->addServer('localhost', 11211); $plugin = new Everyman\Neo4j\Cache\Memcached($memcached); $client->getEntityCache()->setCache($plugin);