views:

22

answers:

2

Hi.

I'm planning on using GAE's TaskQueue API to refresh my cache of HTML pages, which I save in the Datastore (and memcache, but Datastore is more reliable).

Once a week, i add/edit some data, and need to regenerate associated HTML pages, and triggering tasks is the way to do.

Note that different edits may imply changing the same cached page. For instance, the homepage has snippets from several parts from different data. What I want is to launch tasks to the task queue with a delay (using countdown of an hour, for example) so that I can accumulate several edits, and in the end, the cached pages will be regenerated only once.

The problem is, I don't need to add a task to regenerate page X if there is already a task queued to regenerate page X in a hour. Thus, I need to check the task list and see if there is already one.

How can I access the task list?

+2  A: 

I saw that adding the same Task will raise a DuplicateTaskNameError, maybe that´s all I need.

Nuno Cardoso
Correct - this is the purpose of task names. Note that you also need to catch a TombstonedTaskNameError, in case the task has already run.
Nick Johnson
A: 

Whenever you make an edit you could simply remove the item from the cache. Then when someone comes to read a page you would notice that its not in the cache and fetch it from the datastore at that point and update the cache with the newly retrived data. You should already have this kind of logic anyway since you can't always guarantee the item will be in cache. This will impact the speed of the first fetch after you make the updates but after that it will be fine.

dunelmtech
First, some pages are hard to generate, sometimes they pass the 30 second deadline, so it's better to render them offline. Second, I can use the quota for bytes on TaskQueue to make sure my cache is always fresh. But yes, that's the default behaviour.
Nuno Cardoso