bbangert / beaker

WSGI middleware for sessions and caching
https://beaker.readthedocs.org/
Other
517 stars 147 forks source link

How can i update expire time per call or refresh page #233

Open rikhtehgaran opened 8 months ago

rikhtehgaran commented 8 months ago

Hi I have been using the beaker in Bottle framework but I don't know how to update the session cookie expiration time in a beaker it's my code. I need to update the expiration time in the test method when called

import bottle
from beaker.middleware import SessionMiddleware

session_opts = {
    'session.type': 'file',
    'session.cookie_expires': 300,
    'session.data_dir': './data',
    'session.auto': True,

}
app = bottle.Bottle()
subapp = SessionMiddleware(app, session_opts,environ_key="myapp")

@app.route('/test')
def test():
  s = bottle.request.environ.get('myapp')
  subapp.options={'session.cookie_expires': 300}
  s['test'] = s.get('test',0) + 1
  s.save()
  return 'Test counter: %d' % s['test']

bottle.run(app=subapp, port=8000)