Ecosyste.ms: Packages

An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

proxy.golang.org : github.com/icza/gaesession/v2

Package gaesession provides Google App Engine (GAE) support for github.com/icza/session. The implementation stores sessions in the Memcache and also saves sessions in the Datastore as a backup in case data would be removed from the Memcache. This behaviour is optional, Datastore can be disabled completely. You can also choose whether saving to Datastore happens synchronously (in the same goroutine) or asynchronously (in another goroutine), resulting in faster response times. We can use NewMemcacheStore() and NewMemcacheStoreOptions() functions to create a session Store implementation which stores sessions in GAE's Memcache. Important to note that since accessing the Memcache relies on Appengine Context which is bound to an http.Request, the returned Store can only be used for the lifetime of a request! Note that the Store will automatically "flush" sessions accessed from it when the Store is closed, so it is very important to close the Store at the end of your request; this is usually done by closing the session manager to which you passed the store (preferably with the defer statement). So in each request handling we have to create a new session manager using a new Store, and we can use the session manager to do session-related tasks, something like this: Expired sessions are not automatically removed from the Datastore. To remove expired sessions, the package provides a PurgeExpiredSessFromDSFunc() function which returns an http.HandlerFunc. It is recommended to register the returned handler function to a path which then can be defined as a cron job to be called periodically, e.g. in every 30 minutes or so (your choice). As cron handlers may run up to 10 minutes, the returned handler will stop at 8 minutes to complete safely even if there are more expired, undeleted sessions. It can be registered like this: Check out the GAE session demo application which shows how it can be used. cron.yaml file of the demo shows how a cron job can be defined to purge expired sessions. https://github.com/icza/session/blob/master/_gae_session_demo/gae_session_demo.go Limitations based on GAE Memcache: - Since session IDs are used in the Memcache keys, session IDs can't be longer than 250 chars (bytes, but with Base64 charset it's the same). If you also specify a key prefix (in MemcacheStoreOptions), that also counts into it. - The size of a Session cannot be larger than 1 MB (marshalled into a byte slice). Note that the Store will automatically "flush" sessions accessed from it when the Store is closed, so it is very important to close the Store at the end of your request; this is usually done by closing the session manager to which you passed the store (preferably with the defer statement). Check out the GAE session demo application which shows how to use it properly: https://github.com/icza/gaesession/blob/master/_gae_session_demo/gae_session_demo.go

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/icza/gaesession/v2
Keywords: datastore, gae, http-session, memcache
License: Apache-2.0
Latest release: 11 months ago
First release: 11 months ago
Namespace: github.com/icza/gaesession
Stars: 1 on GitHub
Forks: 1 on GitHub
See more repository details: repos.ecosyste.ms
Funding links: https://github.com/sponsors/icza
Last synced: 28 days ago

    Loading...
    Readme
    Loading...