Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

Use memcache for store session data

Project Description

Flask memcache session
=========================

Store session data in memcache

Install
-------

For install you can use pip:
```
pip install flask_memcache_session
```

Usage
-------

app.py
```
from flask.ext.memcache_session import Session
from werkzeug.contrib.cache import MemcachedCache
from flask import Flask, session

app = Flask(__name__)
app.cache = MemcachedCache([host, port])
app.session_interface = Session()

@app.route('/')
def main():
session['x'] = 'The data saved in memcached'
```

Example
-------

```
@app.before_request
def before_request():
g.db = connect(...)
user = g.db.query(models.Users).get(u.decode(session.get('uid', -1)))
g.is_auth = True if user is not None else False

@app.after_request
def after_request(response):
if session.modified and g.is_auth:
user = g.db.query(m.Users).get(u.decode(session.get('uid')))
g.db.add(user)
g.db.commit()
g.db.close()
return response
```

Release history Release notifications

This version
History Node

2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
flask-memcache-session-2.0.tar.gz (1.8 kB) Copy SHA256 hash SHA256 Source None Sep 9, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page