Skip to content

Instantly share code, notes, and snippets.

@kirsn
Created April 3, 2015 17:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirsn/27d50c2863cde0376022 to your computer and use it in GitHub Desktop.
Save kirsn/27d50c2863cde0376022 to your computer and use it in GitHub Desktop.
Web2py cache usage / test script
import time
def print_rows(rows):
print time.ctime()
for row in rows:
print row
db = DAL('sqlite://cache_test.db', pool_size=0)
db.define_table('t1', Field('name',type='string'))
print "%s : Defining disk based cache, with 5 seconds timeout" % time.ctime()
cache_settings = dict(cache=(cache.disk, 5), cacheable=True)
for i in range(10):
record = "A%s" % i
print "Inserting record %s" % record
db.t1.insert(name=record)
time.sleep(2)
print_rows(db(db.t1.id > 0).select(**cache_settings))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment