如何在 ktor 中设置会话超时?
How to set session timeout in ktor?
如果没有用户activity,如何设置会话过期的超时时间?
我正在寻找类似码头的东西:
ServletContextHandler webappContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
...
webappContext.getSessionHandler().setMaxInactiveInterval(timeout_in_sec);
您必须自己实施,这取决于您的 Storage Manger。如果你看最简单的
会话存储在并发映射中
private val sessions = ConcurrentHashMap<String, ByteArray>()
相反,你想要一些能让会话过期的东西。例如你可以使用番石榴缓存
https://github.com/google/guava/wiki/CachesExplained
private val engineCache: Cache<String, ByteArray> = CacheBuilder.newBuilder()
.maximumSize(50)
.expireAfterAccess(30, TimeUnit.MINUTES)
.build()
如果没有用户activity,如何设置会话过期的超时时间? 我正在寻找类似码头的东西:
ServletContextHandler webappContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
...
webappContext.getSessionHandler().setMaxInactiveInterval(timeout_in_sec);
您必须自己实施,这取决于您的 Storage Manger。如果你看最简单的
会话存储在并发映射中
private val sessions = ConcurrentHashMap<String, ByteArray>()
相反,你想要一些能让会话过期的东西。例如你可以使用番石榴缓存 https://github.com/google/guava/wiki/CachesExplained
private val engineCache: Cache<String, ByteArray> = CacheBuilder.newBuilder()
.maximumSize(50)
.expireAfterAccess(30, TimeUnit.MINUTES)
.build()