Alight I'm going to try this one more time and hope it doesn't double
post.
What I've done that I know works for cache of selects on GAE is the
following:
-------------
def gaecache(table,row,criteria):
"""
Returns requested item from memcache or inserts it into memcache for
next call
"""
key = table+str(criteria)
data = memcache.get(key)
if data is None:
selection = db(db[table][row]==criteria).select()
data = selection.as_list(datetime_to_str=False)
memcache.add(key,data,3600)
return data
-------------
With that in one of your models you can just call the function only on
highly accessed queries. You could even make the cache time (3600
seconds above) as an input if you wanted to make the function very
generic.
On Aug 30, 9:20 pm, Chris S <[email protected]> wrote:
> Um... of course that example should also end with "return data".
>
> On Aug 30, 2:23 pm, Jurgis Pralgauskis <[email protected]>
> wrote:
>
>
>
> > I quite use reference fields -- maybe thats the problem...
> > can this be cached the way select is?
>
> > sth like
> > db.define_table("Topics",
> > Field("parent_id","reference Topics", label=T("Parent
> > Topic"), ),
> > Field("name", "string")
> > )
>
> > db.define_table("Examples",
> > Field("topic_id", db.Topics, label="Topic", ),
> > Field("lang_id", db.Languages,label="Language", ),
> > )
>
> > and I use
> > db.Language[example.lang_id]
> > or
> > db.Topics[ db.Topics[example.topic_id].parent_id ]
>
> > On 30 Rugp, 18:01, mdipierro <[email protected]> wrote:
>
> > > It is slow. does it contain a lot of code or a lot of DB IO? I cannot
> > > say without looking at the code.
>
> > > On Aug 30, 9:09 am, Jurgis Pralgauskis <[email protected]>
> > > wrote:
>
> > > > Hello,
>
> > > > I have my beta apphttp://code.google.com/p/code-by-example/
> > > > onhttp://web2py-gae-test.appspot.com/
>
> > > > which seems to load quite
> > > > slowlyhttp://ftp.akl.lt/incoming/jurgio/gae-logs.png
>
> > > > I also tried logs,http://ftp.akl.lt/incoming/jurgio/cbe.profile.txt
> > > > but don't see big problems (though i use profiling for the first
> > > > time..)
>
> > > > ***
> > > > I recently made KEEP_CACHED = True
>
> > > > and for Session use Memcache
> > > > as I use session quite a bit
>
> > > > but still can't feel that its better
>
> > > > ***
> > > > I also see info in logs:
> > > > This request caused a new process to be started for your application,
> > > > and thus caused your application code to be loaded for the first time.
> > > > This request may thus take longer and use more CPU than a typical
> > > > request for your application.
>
> > > > ***http://plugins.jquery.com/project/appear
> > > > might help me a bit,
> > > > as mostly used controller shows ~ 20% of what it loads
>
> > > > I tried web2py_component(action,target) {
> > > > $('#'+target).appear(function() {
> > > > instead of
> > > > jQuery(document).ready(function(){
> > > > but this did' t work :(
>
> > > > any suggestions ?