WebFaction
Community site: login faq
0
1

I have setup memcached as directed in the documentation as well as the directions on this page to setup Django.

In my Django 1.3 settings.py file I have the following:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': 'unix://unix:/home/<username>/memcached.sock',
        }
}

However, everytime I put something in cache and then try to retrieve it again it comes back as None. What could I be doing wrong?

UPDATE

I have tried it with unix:/home/<username>/memcached.sock and still doesn't work.

Here is some test code:

cache_key = "%s_%s" % (request.META['REMOTE_ADDR'], progress_id)

cache.set(cache_key, {
    'length': 'TEST',
    'uploaded': 0
})
data = cache.get(cache_key)

asked 11 Feb '12, 22:49

Dan Olsen
123
accept rate: 0%

edited 11 Feb '12, 23:06


You should only need to have 'unix' in that line once. Could you provide a code example for how you are sending and retrieving the object?

permanent link

answered 11 Feb '12, 22:57

johns
5.4k412
accept rate: 23%

See my update above.

(11 Feb '12, 23:06) Dan Olsen

The official docs show the object name as a string,

>>> cache.set('add_key', 'Initial value')
>>> cache.get('add_key')
'Initial value'

Where as your code is not using strings, try modifying the code to this,

cache_key = "%s_%s" % (request.META['REMOTE_ADDR'], progress_id)

cache.set('cache_key', {
    'length': 'TEST',
    'uploaded': 0
})
data = cache.get('cache_key')
(11 Feb '12, 23:19) johns

On second thought that may not be exactly right, I am not sure what the final product you are trying to create is suppose to look like, or how you are trying to include the first line exactly. Try to modify your code to names that are strings. The cache works based on the names of the entries, so you might have to create a second variable for the 'cache_key' that is on line 1

(11 Feb '12, 23:21) johns

When I run it on my laptop the caching works fine. When I move it to the WebFaction servers it doesn't work.

I've also tried File Based Cache. File based cache is working on my laptop but not on the WebFaction servers.

I am writing a piece that lets me have a upload progress bar on a page.

(11 Feb '12, 23:27) Dan Olsen

Is the memcached.sock file actually at the path that is defined? You can test this with this command,

ls -la /home/<username>/memcached.sock

If the file is there please submit a support ticket so we could look at the account directly.

(11 Feb '12, 23:32) johns
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×337
×34
×28

question asked: 11 Feb '12, 22:49

question was seen: 6,750 times

last updated: 11 Feb '12, 23:32

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM