Author image
Senior Developer

You should use Entity cache

If you have a Drupal 7 site, then you should be using the Entity cache module, here's why:

Lots and lots of things in Drupal are 'entities', such as the content, the users, the taxonomy terms and if you're using contrib modules like Field collection or ECK, then those are entities too.

Most of the time you have some fields on those entities, then every time Drupal needs to load one up, it'll also have to read the data for each field from these tables. Once you start having lots of entities, and potentially field collections on those entities, you can end up with lots of database queries very quickly!

Entity cache can help with the mountain of database queries by storing cached copies of the fully loaded entities in Drupal's cache system.

We've seen this reduce the number of database queries on a page by several hundred!

There are no ill effects to using Entity cached entities if all your code is using Drupal's APIs and not manipulating the data for an entity in the database directly, essentially you can just enable it and forget about it, simple!

We've worked with the module maintainers of ECK to get add Entity cache support and are working with the Field collection maintainers to get Entity cache support there too.

If you have a module that provides entities then you have a small amount of work to do allow Entity cache to support them, but it's easy, and you can see examples in those issues above.

Comments

I ran a comparison of various Drupal performance modules awhile back using Apache Benchmark. In my investigation, I found that under optimal conditions, Entity Cache didn't show a significant performance improvement unless you're dealing with loading large numbers of entities (e.g. > 100) on any given request. Single pages representing single (though complex) entities with many fields, even those with nested entities (e.g. field collections, profile2, etc), and even views of 50 full entities saw negligible improvements.

Here's a view of that Apache Benchmark data, showing Entity Cache vs. No Cache for the "complex entity" and "view of entities" scenarios: http://public.tableausoftware.com/shared/H4WYGQ9MB?:display_count=no

Lullabot also did a nice writeup of Entity Cache with benchmarks and code: http://www.lullabot.com/blog/articles/module-monday-entity-cache

'No cache' is misleading. A part of the reason for the negligible performance change is because entity fields also have the cache_field table where field data regarding entities gets cached into a single row. So while it may not be as quick as all data going into the entity cache table, the number of queries on a page get drastically decreased hence the similarity in performance.

With that said, entitycache is useful for caching other data on entities that may not be fields implemented though hook_entity_load (or hook_node_load, etc) such as with flag, signup modules for example (hence the lullabot example shows a sig. performance boost on user entities).

One task that is useful (regardless of entitycache) is to warm up the entities so they are loaded into cache.

Comments on this article are now closed, if you want to give us feeback you can use our contact form instead.