First time here? Check out the FAQ!
0

How to make askbot work with memcached?

In the settings.py of production server, I added

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

Also added middleware in the file. memcached is started. But when i tried to run askbot in the production mode, it seems like some files, like css file, javascript file, need to be requested from cache. Some links are like: http://xxx.webfactional.com/m/CACHE/js/85190e85e697.js

But it can't be found in the server side. How to configure memcached for the per-site cache?

Many thanks.

jqy3222089's avatar
17
jqy3222089
asked 2013-05-01 08:33:37 -0500, updated 2013-05-03 07:34:36 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

Do you mean that /CACHE/ in the file path means it should be coming from the memcached? Actually - it does not. There is no connection between the /CACHE/ directory and the memory object caching (memcached or any other - at all).

Directory /CACHE/ will be created in your static files directory by the django-compressor app. You will need to make sure to make that directory writeable by the webserver.

It's just a directory name. If your site is working with that configuration, that means your memcached is fine.

Evgeny's avatar
13.2k
Evgeny
answered 2013-05-01 12:48:37 -0500, updated 2013-05-14 14:42:32 -0500
edit flag offensive 0 remove flag delete link

Comments

I didn't use that path for the memcached, it was automatically changed into that way when i turned the debug off.

jqy3222089's avatar jqy3222089 (2013-05-01 18:31:25 -0500) edit

That path has nothing to do with memcached. What makes you think it is?

Evgeny's avatar Evgeny (2013-05-01 18:37:11 -0500) edit

So what should I do when I need to deploy ASKBOT into a production server? Just turn off the debug mode did not work since I have tried this in the server.

jqy3222089's avatar jqy3222089 (2013-05-01 18:55:49 -0500) edit
1

You can't see the .css and .js files? Do you have directory CACHE inside the static files directory? If not - please create it and change permissions so that the webserver can write into that directory.

Evgeny's avatar Evgeny (2013-05-01 18:59:15 -0500) edit

That's the problem. After creating CACHE directory, it's working now. Many thanks!@Evgeny

jqy3222089's avatar jqy3222089 (2013-05-01 19:13:51 -0500) edit

But what was the problem? Can you describe your observation before the fix?

Evgeny's avatar Evgeny (2013-05-01 19:21:12 -0500) edit

The problem is that when I switched askbot into production mode, some static files were failed to be loaded. And some of the address were changed into "/m/CACHE/..."(maybe memcached changed this address?), but in the static directory there was no such directory named CACHE, so I need to manually create it.

jqy3222089's avatar jqy3222089 (2013-05-02 18:45:42 -0500) edit

/m/CACHE/ has no connection with memcached whatsoever, saying this to you third time:). Most likely webserver process could not create directory CACHE due to insufficient privilege of the effective user of the webserver process.

Evgeny's avatar Evgeny (2013-05-02 19:22:56 -0500) edit

@Evgeny: what kind of data will be cached ?

winzer's avatar winzer (2013-05-03 05:39:11 -0500) edit

@Evgeny yes, I see now. :>

jqy3222089's avatar jqy3222089 (2013-05-03 07:33:48 -0500) edit

@koogua - if you have a question about Memcached - please post it separately. The static files and the directory CACHE are not related to memcached at all. Memcached caches the application data, but directory CACHE contains combined js and css files and it is just a directory on disk like any other.

Evgeny's avatar Evgeny (2013-05-03 08:26:36 -0500) edit

I'm having the same problem actually, but my static files are hosted on S3. So it expects the cached CSS, JS etc. to be in the CACHE subfolder on S3. Is this expected? Am I supposed to give permissions to my web server to write to S3? What's the point of creating more new files on S3 though.

kate_r's avatar kate_r (2013-05-14 14:13:05 -0500) edit

@kate_r please look at the django-compressor documentation. Askbot may not be supporting offline asset compilation, but you could give it a try. Google for using <strike>django-staticfiles</strike> django-compressor with S3.

Evgeny's avatar Evgeny (2013-05-14 14:18:32 -0500) edit

In that case, should I disable caching altogether? If so, could I just remove all the CACHE_ variables from settings.py?

kate_r's avatar kate_r (2013-05-14 14:37:05 -0500) edit

err.. I made a mistake - it has to do with django-compressor app and has no connection with caching (like memcached) - at all. Please google django-compressor and Amazon S3.

Evgeny's avatar Evgeny (2013-05-14 14:43:52 -0500) edit

yeah, I've figured that out. :) So could you please explain why Askbot currently expects static files to come from a CACHE subfolder, even they're stored externally?

kate_r's avatar kate_r (2013-05-14 14:45:52 -0500) edit

django-compressor does this. Please read their documentation.

Evgeny's avatar Evgeny (2013-05-14 14:47:42 -0500) edit

Possibly compressor allows to specify custom storage class - maybe you can find one that will store files on S3. Btw, it may also be necessary to use custom file storage for the user-uploaded files in this case.

Evgeny's avatar Evgeny (2013-05-14 15:17:56 -0500) edit

From my understanding, offline compression doesn't work with template inheritance though.

kate_r's avatar kate_r (2013-05-14 16:55:15 -0500) edit

Try custom storage set by configuration for the compressor, maybe that will work.

Evgeny's avatar Evgeny (2013-05-14 17:14:36 -0500) edit

I'll try that. But then, I'm not sure if this has anything to do with the storage class, but if I run python manage.py compress --force, a whole list of errors fire up!

kate_r's avatar kate_r (2013-05-14 17:21:43 -0500) edit
add a comment see more comments