If I have this in my DB:
db = DAL('sqlite://storage.sqlite', check_reserved=[])
db.define_table('test_table',
Field('value'),
)
if db(db.test_table.id > 0).count() == 0:
db.test_table.bulk_insert([{'value': 'one'}, {'value': 'two'},
{'value': 'three'}, {'value': 'four'}, {'value': 'five'}])
And this in my default controller
def index():
test_table_rows = db(db.test_table.id>0).select(cache=(cache.ram,
1800), cacheable=True)
for record in test_table_rows:
# Suppose I want to change the way the values are returned, here
I'm adding a # but I could be
# doing something useful like turning them into an URL()
record.value = record.value + '#'
return {'values': test_table_rows}
Then go to /default/index.json and keep refreshing. What you end up getting
will be something like:
{"values": [{"id": 1, "value": "one##########################"}, {"id": 2,
"value": "two##########################"}, {"id": 3, "value":
"three##########################"}, {"id": 4, "value":
"four##########################"}, {"id": 5, "value":
"five##########################"}]}
I find this behavior to be quite unexpected as I would think that the cached
rows would not be affected, what I would expect would be for the select to
always return me exactly the same cached Rows. This makes cacheable=True very
dangerous in a way that reminds me of using mutables as default function
arguments.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.