Looks like you want to cache the results of the entire function -- so why not do that:
@cache(some_key, time_expire=60, cache_model=cache.ram) def cache_this(): ... rows = db(db.atable.id > 0).select(..., cacheable=True) return dict(rows=rows) Just be sure to set cacheable=True, which will make the entire Rows object cacheable. Anthony On Wednesday, September 13, 2017 at 4:09:23 PM UTC-4, Pierre wrote: > > purpose is to keep a single renewable pseudo-random data sample live > > the w2p books describes a situation of a constant query : > http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=caching+selects#Caching-selects > def cache_db_select(): > logs = db().select(db.log.ALL, cache=(cache.ram, 60)) > return dict(logs=logs) > > now suppose every call a different query like here : > > def cache_this(): > nget = somevalue > kount = db(db.atable.id > 0).count() > offset = randint(0, kount - nget) > limitby = (offset, offset + nget) > rows = db(db.atable.id > 0).select(limitby=limitby, cache=(cache.redis, > 60)) > return dict(rows=rows) > > > > this accumulates cached 'material' and returns a different rows on every call > how do I make *cache_this* behave like the book example ? > > I could cache kount and offset variables as well : > > kount = db(db.atable.id > 0).count(cache=(cache.redis, 60)) > offset = cache.redis('offset', lambda: randint(0, kount-nget), > time_expire=60) > > > but i suppose this would lead to a synchronization problem and thus possible > duplicate cached select > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.