def set_id_represent(update_id_represent_if_elapsed_time=None, id=None):
"""
Calling this function will create in globals the "id_represent" variable if the call is made without
id. If id is passed, it will update the id_represent dictionary with new
id and it representation.
:param id:
:param update_id_represent_if_elapsed_time:
"""
if 'id_represent' not in globals():
global id_represent
id_represent = \
cache.ram('id_represent',
lambda: {r.id: r.represent_field
for r in db().select(db.table_name.id,
db.table_name.represent_field,
orderby=db.table_name.represent_field)
},
time_expire=update_id_represent_if_elapsed_time)
elif isinstance(id, int) or isinstance(id, long):
id_represent_query = \
db(db.table_name.id == id
).select(db.table_name.id,
db.table_name.represent_field,
orderby=db.table_name.represent_field)
id_represent.update({r.id: r.represent_field for r in id_represent_query})
if id:
return id_represent[id]
set_id_represent(update_id_represent_if_elapsed_time=None)
set_id_represent(id=my_id)
I have made some test and print after the id_represent.update(...) above from the function call and the dict seems to be updated... The function that call set_in_represent(id=id) doesn't failed, but when we want to access page which user id_represent[some_id], they all failed for a couples of minutes... Like if the cached dict not get update immediately...--
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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 web2py+un...@googlegroups.com.
Redis keys are stick for ever...I figure out most of how to use the Niphold contrib, though it seems that created cached element stays in Redis for ever... I restart the server and they still there...
errata corrige on BTW2: on redis, time_expire=None results in key stored at most one day. you can always do time_expire=30*24*60*60 for 30days worth.things_to_know: only cache.disk and cache.ram can effectively cache a value indefinitely and enable that strange behaviour of retrieving the previously cached element - that you marked to expire after 5 seconds - one day later.Web2py's cache API is effectively incompatible with any high-performance caching system, unless the user calls upon himself the burden of clearing the cache regularly (which is never the case because cache invalidation is one of the hardest things to master).Both memcache and redis take a more strict behaviour, i.e. the value will effectively expire at the time it was set on the first time. So, you can only fetch a cached value one day later if you originally marked it as expiring one day later. Redis allows a leeway of 120 seconds to accomodate the 90% of the behavioural usecases of cache.ram and cache.disk.
--
So, my main issue with both cache.ram and cache.redis is that new id representation never get added to the dict "permanently". In case of cache.ram, the issue may come from what Anthony explain because I use uwsgi/nginx. But I have made some test with redis and the issue still there, but may still be there for a differents reasons, I don't know. I mean if I update the Redis cached dict from shell, and I try to retrieve the representation passing the key to the dict it works, but it looks like this only works in shell. In case of Redis, I may have to recompute the whole dict base on what you explain, which will not provide any performance improvement if it the case, because what I try to prevent it exactly the creation of the dictionary which requires a lot of computing for nothing each time a new record get created. There maybe something I don't understand about how to refresh Redis cache or in what you explained.
--
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
This is true for any other cache except cache.ram right?
If so, there is no gain with cache.redis the way I use it...
@Anthony, are you sure about the issue with uwsgi/nginx and cache.ram dict update?
I guess, I should start to look at how to get rid of these global dict while not degrading system performance. There surely place where I use these global vars that wouldn't suffer from a little query to the backend, but for grid where the performance was the greatest or simplifying code was acheive with those it will be difficult to stop using them...
--
If I don't use cache.ram dict123 is in globals() and function return the else: part of the function...
--
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 web2py+unsubscribe@googlegroups.com.
id_represent = cache.redis('id_represent',
lambda: db().select(db.mytable.id, db.mytable.field).as_dict(),
time_expire=expiration)
id_represent = db().select(db.mytable.id, db.mytable.field,
cache=(cache.redis, expiration), cacheable=True)
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
--
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 web2py+un...@googlegroups.com.