On Wed, Jun 26, 2013 at 2:49 PM, Tomas Schertel <[email protected]> wrote:
> On Tuesday, 25 June 2013 18:05:46 UTC-3, Jox wrote:
>>
>> I've read the page. So it compiles my templates to python byte code. Does
>> that mean I can load templates faster?
>> But it seems I still have to query database to get data.
>>
>> The website I'm building is my learn-by-do project. It's just a forum
>> running on my linux server or google app engine
>> which my friends and I can play around on it. I know querying database
>> when a request comes in is easy and good
>> enough. I've already implemented serving pages that querying database a
>> lot and render pages with templates every
>> time. I just want to know how could I implement a basic caching mechanism,
>> not a big caching system which has
>> caching strategies and complex algorithms or stuff like that. Just a
>> simple and straight-forward one.
If I am understanding your request properly, you are looking for a way
to cache the generation of dynamic pages until something in the
database has changed; that should be easy to implement, let's see
how.
Given your favorite caching mechanism (memcached, redis, global
dictionary, etc), each time a user request a page you should do a
check like the following:
if 'requested_page' not in cache:
cache['requested_page'] = <generate page by querying the database,
if necessary>
return cache['requested_page']
Then, now that you have your caching mechanism up and running, you
only have to decide a way to invalidate your cache entries (e.g. a new
user is created, a new post is added to a section, etc etc) so that
new requests will trigger the generation of the page and the cache
update:
if <cache invalidation condition>:
del cache['page_to_invalidate'] // or set of pages
My two cents,
Matteo
>
>
> Maybe you should look for a webserver that does it.
> Apache? NGINX?
>
> --
> You received this message because you are subscribed to the Google Groups
> "web.py" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/webpy.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.