开发者

caching and avoiding cached content

开发者 https://www.devze.com 2022-12-08 07:45 出处:网络
I\'ve got a widget with some user editable variables that will only very rarely be updated开发者_如何学编程 (likely only when the user sets up the widget).

I've got a widget with some user editable variables that will only very rarely be updated开发者_如何学编程 (likely only when the user sets up the widget).

Rather than hitting the database, I cache the widget user variables via memcache. The widget content is changing regularly.

I have it set-up so that when the user is creating or editing their widget the widget has a &noCache parameter which avoids the cached content and shows them the most recent version of the widget.

The concern is that the user is going to take the widget variables (including the noCache) and stick that into a page somewhere, thereby completely ignoring the cache.

I was thinking of adding a component which checks the users login, and if the login user matches the widget owner, then don't use the cache. However, that means I'm checking for a user session every time the widget is loaded, and that probably isn't what I want to do.

Any other suggestions on how to do this efficiently?

99.999999% of widget viewers won't be logged in, so i'm trying to add the least overhead to this.


What you should be doing is directly setting the values into memcached as you save them to the database. This way you can have all requests going via the cache, and don't need this workaround.

See Update memcache as your data updates in the memcached FAQ

UPDATE

This does not mean you have to store the raw variables into the memcache. If you are storing the rendered page, by all means render it again and store that result into memcache. If that is "too hard" you could just delete the old data from memcached in the same page that changes the DB and then wait for the next request to find it missing in the cache.

0

精彩评论

暂无评论...
验证码 换一张
取 消