Héllo psychok7,

On Tuesday, January 8, 2013 1:45:07 PM UTC+1, psychok7 wrote:
>
> Hi guys, just wondering if its possible to sort a django cache? I need to 
> add data with an auto increment id to the cache and sort it in reverse 
> order to get it back. I no this can be easily accomplished with the normal 
> mysql database but since the cache is faster i would like to do it there


Yes and no.

Django cache backend alone can't do this sort of things, the only methods 
that are 
defined<https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs#basic-usage>are:

- get
- get_many
- set
- set_many
- incr
- decr
- delete
- delete_many

With those, you can do what you want, you have to set up a «schema» with 
cache keys that will allow you to do what you want.

Similarly you can also do this sort of things using 
redis<http://redis.io/commands>, 
which is also pretty fast since it's also a in memory key/value store, 
using higher level methods on higher level data structures like lists, 
sets, sorteds sets, hashes. You might as well fallback on creating your own 
data structures relying on existing datastructures usings 
scripts<http://redis.io/commands#scripting>
.

The usecase you are discribing is not clear, why not just do the sorting 
with mysql, store in the cache with an expiration key the results, ids or 
rendered templates ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/izl57HRb4YUJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to