tags:

views:

64

answers:

1

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.

+2  A: 

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.

Tom Leys
I can't believe I didn't think of that! thanks.
pedalpete
Oh wait! I can't do that. I'm caching the results of the php page, and as I mentioned in the original question, the content of the page changes quite regularly (based on variables passed to the widget). Your solution means that I am not setting the variables in the php page, but rather setting the variables in the memcache. This would still reduce db load, however the quickest way to build the page is to have everything held in the memcache, not just the variables.
pedalpete