{"id":21560412,"url":"https://github.com/icza/gaesession","last_synced_at":"2025-03-18T04:27:12.116Z","repository":{"id":57496484,"uuid":"195391644","full_name":"icza/gaesession","owner":"icza","description":"Google App Engine (GAE) support for github.com/icza/session","archived":false,"fork":false,"pushed_at":"2023-07-03T07:14:36.000Z","size":41,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T11:13:20.553Z","etag":null,"topics":["datastore","gae","http-session","memcache"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"icza"}},"created_at":"2019-07-05T10:37:35.000Z","updated_at":"2023-05-10T03:23:12.000Z","dependencies_parsed_at":"2024-06-20T17:24:43.657Z","dependency_job_id":"ee379049-098a-426b-a039-4572ca232699","html_url":"https://github.com/icza/gaesession","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icza%2Fgaesession","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icza%2Fgaesession/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icza%2Fgaesession/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icza%2Fgaesession/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icza","download_url":"https://codeload.github.com/icza/gaesession/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244155680,"owners_count":20407399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datastore","gae","http-session","memcache"],"created_at":"2024-11-24T09:14:18.931Z","updated_at":"2025-03-18T04:27:12.096Z","avatar_url":"https://github.com/icza.png","language":"Go","funding_links":["https://github.com/sponsors/icza"],"categories":[],"sub_categories":[],"readme":"# gaesession\n\n[![GoDoc](https://godoc.org/github.com/icza/gaesession?status.svg)](https://godoc.org/github.com/icza/gaesession)\n\nGoogle App Engine (GAE) support for https://github.com/icza/session.\n\nThe implementation stores sessions in the Memcache and also saves sessions in the Datastore as a backup\nin case data would be removed from the Memcache. This behaviour is optional, Datastore can be disabled completely.\nYou can also choose whether saving to Datastore happens synchronously (in the same goroutine)\nor asynchronously (in another goroutine), resulting in faster response times.\n\nWe can use `NewMemcacheStore()` and `NewMemcacheStoreOptions()` functions to create a session Store implementation\nwhich stores sessions in GAE's Memcache. Important to note that since accessing the Memcache relies on\nAppengine Context which is bound to an `http.Request`, the returned Store can only be used for the lifetime of a request!\nNote that the Store will automatically \"flush\" sessions accessed from it when the Store is closed,\nso it is very important to close the Store at the end of your request; this is usually done by closing\nthe session manager to which you passed the store (preferably with the defer statement).\n\nSo in each request handling we have to create a new session manager using a new Store, and we can use the session manager\nto do session-related tasks, something like this:\n\n    ctx := appengine.NewContext(r)\n    sessmgr := session.NewCookieManager(gaesession.NewMemcacheStore(ctx))\n    defer sessmgr.Close() // This will ensure changes made to the session are auto-saved\n                          // in Memcache (and optionally in the Datastore).\n\n    sess := sessmgr.Get(r) // Get current session\n    if sess != nil {\n        // Session exists, do something with it.\n        ctx.Infof(\"Count: %v\", sess.Attr(\"Count\"))\n    } else {\n        // No session yet, let's create one and add it:\n        sess = session.NewSession()\n        sess.SetAttr(\"Count\", 1)\n        sessmgr.Add(sess, w)\n    }\n\nExpired sessions are not automatically removed from the Datastore. To remove expired sessions, the package\nprovides a `PurgeExpiredSessFromDSFunc()` function which returns an [http.HandlerFunc](https://golang.org/pkg/net/http/#HandlerFunc).\nIt is recommended to register the returned handler function to a path which then can be defined\nas a cron job to be called periodically, e.g. in every 30 minutes or so (your choice).\nAs cron handlers may run up to 10 minutes, the returned handler will stop at 8 minutes\nto complete safely even if there are more expired, undeleted sessions.\nIt can be registered like this:\n\n    http.HandleFunc(\"/demo/purge\", gaesession.PurgeExpiredSessFromDSFunc(\"\"))\n\nCheck out the GAE session demo application which shows how it can be used.\n[cron.yaml](https://github.com/icza/gaesession/blob/master/_gae_session_demo/cron.yaml) file of the demo shows how a cron job can be defined to purge expired sessions.\n\nCheck out the [GAE session demo application](https://github.com/icza/gaesession/blob/master/_gae_session_demo/gae_session_demo.go) which shows how to use this in action.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficza%2Fgaesession","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficza%2Fgaesession","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficza%2Fgaesession/lists"}