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
```
=========================
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
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file flask-memcache-session-2.0.tar.gz
.
File metadata
- Download URL: flask-memcache-session-2.0.tar.gz
- Upload date:
- Size: 1.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d93374dd8b7de0536d50ef953dec1b72f45265ced009c15982f8ff25aec02343 |
|
MD5 | 62f92774d63a4478c25e0b7831910ea1 |
|
BLAKE2b-256 | de9e088eb2ec1ca14f89945a3a6884b25a252d34575168ceaa62d7e4a3afe494 |