Hey Guys,
I am writing a custom module which basically restricts people from editing all the fields in their cck node. So I do node_load, grab just the bits of information they are allowed to change, put it in a basic drupal form and then do a sql update to change the values to the new values they give me. However Drupal is caching the initial values, so once they have saved the form and then go straight straight back into it again it shows them the initial values and looks like it hasn't saved the date (I have checked in the db and the details are saved). I know it is caching because if I go to Site Performance and clear the cache the form then shows the correct new values.
Is there a way to exclude that custom created form from caching or somehow clear the cache before I populate the values or something?
Thanks so much for any help :)
Comments
Hey, It may be advisable to
Hey,
It may be advisable to use node_save instead of a manual update, as you would be skipping the step of allowing other modules to process the new node data. There's an example of the node_save usage here - http://drupal.org/node/351426.
As for the cacheing stuff, there's a 'reset' parameter which will instruct Drupal to clear the node_load cache before loading.
So you'd write:
node_load(nodeid, null, true);
Hope that helps.
Thanks
Hey Guy,
Thanks so much for your help - much appreciated. Unfortunately just putting in the node_load(nodeid, null, true) doesn't seem to be doing the trick so it looks like I'll have to use node_save (which I was just hoping to avoid out of laziness, having to rewrite the code).
Thanks again!
cache clear
No problem at all,
Try using cache_clear_all().
I was just looking at the node_save function and that does a call to "cache_clear_all()" at the end.
Since it works when you do that manually, that may well fix the problem... and save you rewriting your function!
Node_save
Tried cache_clear_all() but it didn't seem to do the trick - I may not have had it in quite the right place. Decided to stop being lazy and just rewrite my function using node_save. Now it is working like a charm.
Thanks!
nice
Well done on sorting it out. I must say writing your own save routine sounds like the opposite of lazy to me though!