How to update widget from widget() function?

Huh. It had never actually occurred to me to use widget instance as cache. I hadn’t ever seen such implementation either.

This is quite an original idea, and as such it is hard to accurately point out benefits and issues with implementation. For starters update() doesn’t actually save anything, it just used as check for actual save and I won’t say where saving even happens from quick look because it’s abstracted deeper.

From my experience the more traditional implementation would be to cache using more conventional approach (such as transients) and tie it to API, not to widget.

As argument for that imagine user puts two different instances of widget in two different sidebars, but configures them the same way. They will be polling API at double rate, while they actually need exactly same data from API and could (and should) share it.

Leave a Comment