Neo4j Internals: Caching
Chris Gioran explains how Neo4j is using internal caching layers for optimizing access to nodes and relationships:
First note that there are two caches, one for nodes and one for relationships, which apart from storing different classes, they can have different maximum sizes (via
max_node_cache_sizeandmax_relationship_cache_sizeconfiguration parameters), albeit not different implementations. There are 4 different kinds of cache implementations, all in packageorg.neo4j.kernel.impl.cache. There is the degenerateNoCache, which stores nothing.LruCacheuses a good oldLinkedHashMapwith an overriddenremoveEldestEntry()which makes it an LRU cache and provides adaptability (more on that later). Finally,{Soft,Weak}LruCacheprovide the exact same implementation, with Weak and Soft interchanged, utilizing{Soft,Weak}Valuesto store references andReferenceQueuesto store garbage collected references. They both extendorg.neo4j.kernel.impl.cache.ReferenceCache, which defines apollClearedValues()method for removing “dead” entries from the map. By the way, this is the end of the code for adaptability for ReferenceCaches, meaning that their adaptation to the current memory utilization is whatever the Weak/SoftReference + the gc can offer (which is a lot). All management of the content of the caches is performed exclusively byNodeManager, while the actual memory consumption is determined by theAdaptiveCacheManagerand is influenced by the user-supplied configuration.
Original title and link: Neo4j Internals: Caching (NoSQL databases © myNoSQL)
via: http://digitalstain.blogspot.com/2010/10/neo4j-internals-caching.html