You place

  videos=db(db.video.id>0).select(cache=(cache.ram,0))

where you want the videos to be extracted from db.

  videos=db(db.video.id>0).select(cache=(cache.ram,3600))

everywhere you need to get the list of videos.

On Jul 23, 4:38 am, Adi <[email protected]> wrote:
> But where will I place this query, for "videos" to be accessible
> everywhere else?
>
> On Jul 23, 2:29 pm, mdipierro <[email protected]> wrote:
>
> > videos=db(db.video.id>0).select(cache=(cache.ram,3600))
>
> > 3600 are seconds and it is the cache time. If you replace the value
> > with 0, it will be re-computed.
>
> > On Jul 23, 4:13 am, Adi <[email protected]> wrote:
>
> > > Hi all,
>
> > > I have this use-case:
>
> > > There is a set of rows being queried from the database.
>
> > > videos=db(db.video.id>0).select()
>
> > > Now I have three different views (in same controller) where I want to
> > > access these rows (with additional filters), but I want to prevent
> > > multiple db calls.
>
> > > def index():
> > >      # use videos here with an additional filter
> > >     home_videos = [v for v in videos if v.folder == 'home']
>
> > > def favorites():
> > >     fav_videos = [v for v in videos if v.folder == 'favorites']
>
> > > These views essentially fetch subset of the same dataset and display
> > > them.
>
> > > Question:
> > > -------------
> > > Is there a way to "cache" the first db call "videos = ... " and be
> > > able to access "videos" variable without hitting database again, as
> > > long as this session exists?
>
> > > I am not sure if and how I can use global variables here, and will
> > > they reliably persist.

Reply via email to