thanks Anthony! it's working with lazy_cache decorator. I guess the @ is missing in the documentation example: lazy_cache('key', time_expire=60, cache_model='ram') def f(a,b,c,): ....
Alex Am Sonntag, 5. Januar 2014 16:20:37 UTC+1 schrieb Anthony: > > If you want to do it with a decorator, you can use @lazy_cache (see > http://web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules). > > Otherwise, you can just use current.cache to store the return value of the > function. > > Anthony > > On Sunday, January 5, 2014 8:13:59 AM UTC-5, Alex wrote: >> >> I've quite a lot model files (~40), so far the performance is still very >> good. Since it is not very optimal and also not good in the long run I'm >> now thinking of rewriting the code into modules. >> >> I'm struggling a little bit to rewrite the functions. E.g. consider >> following function in a model: >> @cache('room.count', 3600, cache.ram) >> def getRoomCount(): >> return db(db.room.id > 0).count() >> >> >> how do I write this in a module so I can access cache? >> >> thanks, >> Alex >> >> Am Mittwoch, 1. Januar 2014 03:01:18 UTC+1 schrieb Wei Li: >>> >>> Thank you all for the replies! >>> >>> >>> On Tue, Dec 31, 2013 at 1:10 PM, Phil Hughes <nic...@gmail.com> wrote: >>> >>>> Add an argument to the function: foo(bar): Only functions with no >>>> arguments can be called from the outside world. >>>> >>>> >>>> On Tuesday, December 31, 2013 3:57:56 AM UTC-6, Wei Li wrote: >>>>> >>>>> Hi, >>>>> >>>>> This could be a silly question:) . I am going to build up some >>>>> application logic. So I will create a few class and functions. Looks like >>>>> it's not very good to put these code under controllers. Although from the >>>>> manual, it says controller folder is for application logic and workflow. >>>>> See if I have a function >>>>> >>>>> def foo(): >>>>> return <SOME_SENSITIVE_INFORMATION> >>>>> >>>>> >>>>> I don't want to put this function in controllers/default.py because >>>>> people can see the return value of foo() through >>>>> http://myapp/default/foo which is not expected. I just want foo() to >>>>> be a normal function instead of a controller function. >>>>> >>>>> So my question is where is the best place to put my own application >>>>> logical codes indeed? There are three places that I can put python codes >>>>> into: >>>>> >>>>> >>>>> - *models* describe a representation of the data as database >>>>> tables and relations between tables. >>>>> - *controllers* describe the application logic and workflow. >>>>> - *modules *are other optional Python modules. >>>>> >>>>> >>>>> Looks like to me *modules *is the best place. But the new problem is >>>>> the global objects and classes are not visible to files in modules unlike >>>>> files in models/controllers. I am not sure which packages need to be >>>>> imported. It will be convenient if *modules *folder can be treated >>>>> same as models/controllers? >>>>> >>>>> Any suggestion is appreciated. >>>>> >>>>> Thanks, >>>>> Wei >>>>> >>>> -- >>>> 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 a topic in the >>>> Google Groups "web2py-users" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/web2py/EqplHGT6SHI/unsubscribe. >>>> To unsubscribe from this group and all its topics, send an email to >>>> web2py+un...@googlegroups.com. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>> >>> -- 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/groups/opt_out.