Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/russian-developer/Flask-memcache-session
Adds the ability to use as a storage memcache
https://github.com/russian-developer/Flask-memcache-session
Last synced: 3 months ago
JSON representation
Adds the ability to use as a storage memcache
- Host: GitHub
- URL: https://github.com/russian-developer/Flask-memcache-session
- Owner: russian-developer
- License: bsd-3-clause
- Created: 2011-10-12T09:06:05.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2018-01-25T19:46:32.000Z (almost 7 years ago)
- Last Synced: 2024-08-15T20:02:38.012Z (4 months ago)
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 18
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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, sessionapp = 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
```