Great. That's what I was looking for - in memory filtering. Will try
and let you know!

On Jul 23, 3:02 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> No because they two queries are different. The second query will not
> find the cached results from the first and pull them again.
>
> You can do
>
> def index():
>     videos = db( myquery ).select(cache=(cache.ram,0)) # myquery is
> across multiple tables, with joins.
>
> def favorites():
>    fav_videos =db( myquery ).select(cache=(cache.ram,
> 3600)).find(lambda row: row.video.folder=='favorites')
>
> The find command will give you a subset of an existing Rows object (in
> this case the cached one)
>
> On Jul 23, 4:52 am, Adi <aditya.sa...@gmail.com> wrote:
>
>
>
> > Ok I'm going to bug you a little more till I understand this well
> > enough :)
>
> > there are two functions in controller:
> > def index():
> >     # here I will hit database because user first comes here
> >     videos = db( myquery ).select(cache=(cache.ram,0)) # myquery is
> > across multiple tables, with joins.
>
> > def favorites():
> >     # here I want to get a subset of "videos"
> >    fav_videos = db( myquery & db.videos.folder ==
> > 'favorites').select(cache=(cache.ram, 3600))
> >    # this query should not hit database because of the earlier query
> > in index()
>
> > Is this the correct behavior?
>
> > On Jul 23, 2:45 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > 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 <aditya.sa...@gmail.com> wrote:
>
> > > > But where will I place this query, for "videos" to be accessible
> > > > everywhere else?
>
> > > > On Jul 23, 2:29 pm, mdipierro <mdipie...@cs.depaul.edu> 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 <aditya.sa...@gmail.com> 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