Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some memcache servers requiere username and password #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions newcache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"Modified memcached cache backend"

import time
import os

from threading import local

Expand Down Expand Up @@ -52,10 +53,12 @@ def get_key(key):

class CacheClass(BaseCache):

def __init__(self, server, params):
def __init__(self, server, params, username=None, password=None):
super(CacheClass, self).__init__(params)
self._servers = server.split(';')
self._use_binary = bool(params.get('binary'))
self._use_binary = bool(params.get('BINARY'))
self._username = os.environ.get('MEMCACHE_USERNAME', username)
self._password = os.environ.get('MEMCACHE_PASSWORD', password)
self._local = local()

@property
Expand All @@ -69,9 +72,11 @@ def _cache(self):

# Use binary mode if it's both supported and requested
if using_pylibmc and self._use_binary:
client = memcache.Client(self._servers, binary=True)
client = memcache.Client(self._servers, binary=True,
username=self._username, password=self._password)
else:
client = memcache.Client(self._servers)
client = memcache.Client(self._servers,
username=self._username, password=self._password)

# If we're using pylibmc, set the behaviors according to settings
if using_pylibmc:
Expand Down