-
Notifications
You must be signed in to change notification settings - Fork 137
Caching
jadell edited this page Oct 7, 2013
·
3 revisions
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 Everyman\Neo4j\Cache
interface.
The following client methods interact with the cache:
-
Client::deleteNode()
andClient::deleteRelationship()
- Removes the entity by id from the cache. -
Client::getNode()
andClient::getRelationship()
- Looks up the entity by id in the cache and returns it. Multiple calls return the same object. -
Client::loadNode()
andClient::loadRelationship()
- Looks up the entity by id in the cache, and loads its properties into the supplied entity. -
Client::saveNode()
andClient::saveRelationship()
- Stores the entity by id in 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);