Re: [web2py] Re: Auth Decorator / Model Question.

2012-09-04 Thread Kevin Cackler
Great, thanks.  I spent the first few days having web2py create our 
database tables from our models and now we're moving on to actual coding.


I am LOVING this framework!

Kevin Cackler
Tech Daddies
501-205-1512
http://www.techdaddies.com

On 9/4/2012 3:18 PM, Anthony wrote:


In my limited experience with web2py, I'm thinking I should store
the code in a model file and have that code save the store info to
a web2py session, but I wanted to get a second opinion before
continuing down that path.


Yes, that's exactly right.

Anthony
--





--





Re: [web2py] Re: Auth Decorator / Model Question.

2012-09-04 Thread Kevin Cackler
Every store has a unique URL (So store.mysite.com) which will be the key 
we look up on.  This is why the session trick will work.  Because we are 
storing the store data for store.site.com in session.store.mysite.com so 
every store would have a unique session.


I guess the real question is - Should we just cache this query result or 
should we store it in a session?  Which way is preferred for Python / 
web2py development?


Kevin Cackler
Tech Daddies
501-205-1512
http://www.techdaddies.com

On 9/4/2012 3:22 PM, Niphlod wrote:

you can certainly do

STORE_DETAILS = db(db.stores.user_id == auth.user_id).select()

in models.
You'd have the variable STORE_DETAILS available in all controllers and 
every time a user loads a page the data will be refreshed.


In order to reduce the db pressure, you can

STORE_DETAILS = db(db.stores.user_id == 
auth.user_id).select(cache=(cache.ram, 60))


Doing so, the 2nd select will be fired only if more than 60 seconds 
passed from the 1st (i.e. a new page requested by the same user within 
60 seconds will be fetched from the cache and not from the db)


What you are doing in php works for web2py also: if you are positive 
that once a user is logged-in he would get the same stores forever (so 
it's not necessary to fetch the data every time you load the page), 
you can cache it with a high number or simply store the store details 
in session, i.e.


if not session.store_details: #so it will be fetched one time only, if 
no store_details key is found on session

  store_details = db(db.stores.user_id == auth.user_id).select()

Then you'd have to access this data as session.store_details

That's all if I got it correctly: if I didn't understand please post 
more details.


--





--





Re: [web2py] Re: Auth Decorator / Model Question.

2012-09-04 Thread Bruno Rocha
cache.ram or even better (memcached) is preferred! if you use session and
your sessions are stored on filesystem, if you have too much data it will
be hard to load on each request.

DATA = cache.ram(request.http_host, lambda: db(..).select(cacheable=True),
86400) # keeps for 24  hours.

Now, on every place where data is changed you can call
cache.ram.clear(regex=None) to reset that cache.

-- 





Re: [web2py] Re: Auth Decorator / Model Question.

2012-09-04 Thread Anthony
Note, sessions are specific to individual users (clients). If you put 
something in session.store.mysite on a given request, it will only be 
available to that specific user, not to anyone who goes to the 
store.mysite.com URL. If you need data accessible to all users store-wide, 
you should put it in the cache.

Anthony

On Tuesday, September 4, 2012 4:26:02 PM UTC-4, Kevin C wrote:

 Every store has a unique URL (So store.mysite.com) which will be the key 
 we look up on.  This is why the session trick will work.  Because we are 
 storing the store data for store.site.com in session.store.mysite.com so 
 every store would have a unique session. 

 I guess the real question is - Should we just cache this query result or 
 should we store it in a session?  Which way is preferred for Python / 
 web2py development? 

 Kevin Cackler 
 Tech Daddies 
 501-205-1512 
 http://www.techdaddies.com 

 On 9/4/2012 3:22 PM, Niphlod wrote: 
  you can certainly do 
  
  STORE_DETAILS = db(db.stores.user_id == auth.user_id).select() 
  
  in models. 
  You'd have the variable STORE_DETAILS available in all controllers and 
  every time a user loads a page the data will be refreshed. 
  
  In order to reduce the db pressure, you can 
  
  STORE_DETAILS = db(db.stores.user_id == 
  auth.user_id).select(cache=(cache.ram, 60)) 
  
  Doing so, the 2nd select will be fired only if more than 60 seconds 
  passed from the 1st (i.e. a new page requested by the same user within 
  60 seconds will be fetched from the cache and not from the db) 
  
  What you are doing in php works for web2py also: if you are positive 
  that once a user is logged-in he would get the same stores forever (so 
  it's not necessary to fetch the data every time you load the page), 
  you can cache it with a high number or simply store the store details 
  in session, i.e. 
  
  if not session.store_details: #so it will be fetched one time only, if 
  no store_details key is found on session 
store_details = db(db.stores.user_id == auth.user_id).select() 
  
  Then you'd have to access this data as session.store_details 
  
  That's all if I got it correctly: if I didn't understand please post 
  more details. 
  
  -- 
  
  
  



--