On Fri, Feb 11, 2011 at 4:37 PM, Raoul <raoul.th...@gmail.com> wrote:
> Hi,
>
> I am not sure if this is a bug, but currently not usable as it should,
> at least in my case?
>
> Having similar in my in-memory statistic collector:
>
>>>> from django.core.cache import cache
>>>> cache.set('testA', 0)
>>>> cache.set('testB', 1)
>>>> cache.incr('testA')
> 1
>>>> cache.incr('testB')
> 2
>>>> cache.get('testA')
> 1
>>>> cache.get('testB')
> 2
>>>>
>
> Now, when I try to fetch a dict using _cache, my values are no longer
> integers:

Who/what said you should do this? The '_' prefix denotes that this is
private to django.core.cache.cache.

>
>>>> cache._cache
> {'testA': 'I1\n.', 'testB': 'I2\n.'}
>>>> cache._cache['testA']
> 'I1\n.'
>>>> type(cache._cache['testA'])
> <type 'str'>
>
> whereas the stored value is still of type INT:
>>>> type(cache.get('testA'))
> <type 'int'>

Yes, they are pickled, thats how values are put into the cache. If you
use the public API, then that is all worked out for you.

>
> I would use pickle.dumps(cache._cache) to serialize the output and
> download to my Cacti server to have some nice graphs, but instead I
> had to use something like:
>
> map = {}
> for key in cache._cache.keys():
>    map[key] = cache.get(key)
>    # Serialise map
>    stats = pickle.dumps(map)
>
> If more people share my opinion, I will file a bug.
>
> Thanks
> Raoul
>

A bug report for django.core.cache.cache._cache not behaving how you
like would probably not go down well. It behaves as it should.

Cheers

Tom

-- 
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 
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