Some of the information here may be outdated, please check the book instead


This recipe is about web2py using RAM MEMORY for "disk caching" on linux(with TMPFS).

Ok, to the point:

You have to be logged in as root. Then you type:

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


$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:



@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',

[ 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.

© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.