If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

CACHE QUOTA

You may want to use cache.disk with tmpfs. Here is how:

(You have to be logged in as root)

mount -t tmpfs tmpfs $folder_path -o rw,size=$size

where:

$folder_path is a path to the folder where you mount your slice of RAM

$size is the amount of memory you want to dedicate( M - megabytes )

for example:

mkdir /var/tmp/myquery
mount -t tmpfs tmpfs /var/tmp/myquery -o rw,size=200M

You have just allocated 200M of your RAM. Now we have to map it in web2py application.

Since 03-11-2010 all of this is even easier an better, you just write in your models:

from gluon.cache import CacheOnDisk
cache.disk = CacheOnDisk(folder='/the/memory/mapped/folder')

so in our case:

cache.disk = CacheOnDisk(folder='/var/tmp/myquery')

and than:

db(...).select(cache=(cache.disk,3600)....)

or:

@cache(request.env.path_info, time_expire=5, cache_model=cache.disk)
def cache_controller_on_disk():
    import time
    t = time.ctime()
    return dict(time=t, link=A('click to reload',_href=request.url))

[ controller example comes from the web2py book ]

this way you can have "ram space quota" for every query/controller/etc cached, and each one can have different size setting.

Related slices

Comments (0)


Hosting graciously provided by:
Python Anywhere