query cahing in neo4j?

271 views
Skip to first unread message

charu tyagi

unread,
Apr 8, 2012, 12:16:27 PM4/8/12
to Neo4j
is query caching present in neo4j??????????reply me plzzzzzzzzzz as
soooon as possible

James Thornton

unread,
Apr 8, 2012, 1:23:33 PM4/8/12
to ne...@googlegroups.com

On Sunday, April 8, 2012 11:16:27 AM UTC-5, charu tyagi wrote:
is query caching present in neo4j??????????reply me plzzzzzzzzzz as
soooon as possible


Neo4j doesn't cache the actual query, but you can accomplish this by returning the element IDs instead of returning the actual elements, 

Cache the element ID list in your app (or in Redis, etc), and use Cypher to do a mutli-get on the IDs: 

START x = node({ids} RETURN x

Neo4j caches the elements as they are accessed. If the entire DB fits in memory, you can you use Gremlin to warm the cache...

def warm_cache() {
  for (vertex in g.getVertices()) {
    vertex.getOutEdges()
  }
}

...otherwise, the elements will be cached after they are first accessed.

- James


- James
 

Andres Taylor

unread,
Apr 8, 2012, 1:27:58 PM4/8/12
to ne...@googlegroups.com
On Sun, Apr 8, 2012 at 7:23 PM, James Thornton <james.t...@gmail.com> wrote:

On Sunday, April 8, 2012 11:16:27 AM UTC-5, charu tyagi wrote:
is query caching present in neo4j??????????reply me plzzzzzzzzzz as
soooon as possible


Neo4j doesn't cache the actual query

Actually, it does. Cypher has a LRU cache capped to 100 queries. It saves the server from having to parse the query and then construct an execution plan.

What you can do to make sure to use it effectively is to use parameters instead of hand-crafting strings.

And Charu  - please write in a more coherent manner. That's just annoying to read.

HTH,

Andrés 

Michael Hunger

unread,
Apr 8, 2012, 1:33:03 PM4/8/12
to ne...@googlegroups.com
And for warming up the caches for your queries you can actually execute statements once upfront.

To load all nodes and relationships something like this cypher query is useful:

start n=node(*) match n-->() return count(*)

Michael

James Thornton

unread,
Apr 8, 2012, 1:37:03 PM4/8/12
to ne...@googlegroups.com


On Sunday, April 8, 2012 12:27:58 PM UTC-5, Andres Taylor wrote:


On Sun, Apr 8, 2012 at 7:23 PM, James Thornton <james.t...@gmail.com> wrote:

On Sunday, April 8, 2012 11:16:27 AM UTC-5, charu tyagi wrote:
is query caching present in neo4j??????????reply me plzzzzzzzzzz as
soooon as possible


Neo4j doesn't cache the actual query

Actually, it does. Cypher has a LRU cache capped to 100 queries. It saves the server from having to parse the query and then construct an execution plan.


Hi Andres -

Does Cypher cache the query results, or the query plan? 

On an expensive query, would it be more efficient to resuse the cached Cypher query or to cache the IDs in your app and do a multi-get in Cypher, ?

- James


Andres Taylor

unread,
Apr 8, 2012, 1:45:13 PM4/8/12
to ne...@googlegroups.com
On Sun, Apr 8, 2012 at 7:37 PM, James Thornton <james.t...@gmail.com> wrote:
Hi Andres -

Does Cypher cache the query results, or the query plan? 

It caches the execution plan, not the query result.

 
On an expensive query, would it be more efficient to resuse the cached Cypher query or to cache the IDs in your app and do a multi-get in Cypher, ?

Not sure what you mean here. In general - it depends. Caching always brings the problem of cache invalidation. Sometimes it's OK to cache wildly on the app layer, and sometimes it's not. 

Efficient means nothing if the data returned is unacceptably outdated.

That's my POV at least. Do I make sense?

Andrés
Reply all
Reply to author
Forward
0 new messages