I have a computed field that lists content related to a node, so it's value should be changed when I add a new node. Whenever, I add a new node I need to clear the cache to update the computed field's value.

How do I prevent caching value of the computed field OR re-compute the value after adding a new node?


Check out the rules module (http://drupal.org/project/rules):

The Rules module allows site administrators to define conditionally executed actions based on occurring events (known as reactive or ECA rules).

You could add a rule to clear the cache whenever a new nodes has been added.

It's not exactly the way you asked for, but it gets the job done - updating the computed field's value whenever a new node has been created.

  • Curiosity: which Rules ACTION would you use to clear the cache? I'm ot aware of any such Rules Action, hence my curiosity ... Nov 5 '16 at 19:09

I haven't used this module in a while, and don't have the quick ability to do so now, but I recall you can set the fields up two ways, one that relies on the database and cron/caches, and the other that runs on each node view.

A quick look at the module page has this snippet:

You can also choose whether to store your computed field values in the database with other content fields, or have them "calculated" on the fly during node views.

so I would look into that option. I am pretty sure that if you store it in the database it only updates when that particular node is updated, but if you don't store it in the database, it is run on each node view. (Somewhat obviously this will have a performance impact if the computations are complex.)

  • 2
    It seems like a problem with page cache to me. I had similar one - computed field did not appear updated as node hosting it was not recalculated, just served from page cache (in my case from Boost, to be honest, but that's quite the same).
    – Mołot
    Jul 19 '13 at 7:02
  • Hmmm. Good point @molot. If this is happening for anonymous users only, definitely something to look into. Perhaps a custom module node_save() that clears the page cache for just that node/# path...
    – Jimajamma
    Jul 19 '13 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.