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