How to check that cache is functioning

  • make an example like this:
  • def index():
        cached = db(db.my_table.id>0).select(cache=(cache.ram,20))
        if db._lastsql:
            print db._lastsql  # will return result 1st time and when cache expires
        else:
            print 'no result'
        return dict(cached=cached)
    
  • as you’ll notice :
    db._lastsql # will return result 1st time and when cache expires
  • Oh… !!, in general cache anything in ram/disk using something like:

    variable=cache.ram('key',lambda: create_variable(),3600)
    # cache.ram or cache.disk
    

    How it works?

    If a ‘key’ variable is in the cache.ram and is not older than 3600
    seconds it returns else calls create_variable, stores it in cache and
    returns its value.
    Of course, you can replace “key” with any name you want.


    Advertisements

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    %d bloggers like this: