Hi guys,

I was wondering if somebody could help me with deserialization.

I'm currently trying to cache the result of a database query using a
JSON serializer in (what I assume to be) the standard fashion:

-----------
def cache_query(id):
    cache_key = "cache_key_" % id
    item = cache.get(cache_key)

    if item is None:
        item_obj = Item.objects.filter(id=id)
        item = serializers.serialize("json", item_obj,
ensure_ascii=False)
        cache.set(cache_key, item, 30) # I've just chosen a random
number for seconds here
    item_deserial = list(serializers.deserialize("json", item))
[0].object

    return item_deserial
------------

It seems like the deserializer is talking to the database in order to
reconstruct the queryset. I may be wrong on this, but commenting out
the deserializer line reduces the number of queries by the amount I'd
expect if it was not talking to the database. It's obviously quite
helpful reconstructing a queryset (as you can follow foreign key
relationships etc), but is there anyway to purposely prevent it from
recontacting the database? Is it even contacting the database?

I'd really like to minimise the number of queries and I don't need the
full flexibility of a Queryset, a dictionary of the values would be
more than adequate for what I'm doing, which I could extract from the
serialized values (after a bit of eval/str fun!).

If somebody could point out any obvious errors with my code, I'd be
really grateful! I'm very new the caching, so any pointers would be
great.

Kind regards,

Mike.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to