{"id":13508139,"url":"https://github.com/gutschilla/plug-session-memcached","last_synced_at":"2025-10-21T18:41:25.569Z","repository":{"id":24865490,"uuid":"28281060","full_name":"gutschilla/plug-session-memcached","owner":"gutschilla","description":"Store your plug sessions in memcached","archived":false,"fork":false,"pushed_at":"2019-12-18T17:17:59.000Z","size":34,"stargazers_count":15,"open_issues_count":2,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-03T08:57:37.315Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gutschilla.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-20T22:27:49.000Z","updated_at":"2023-09-01T10:53:23.000Z","dependencies_parsed_at":"2022-08-22T17:40:10.934Z","dependency_job_id":null,"html_url":"https://github.com/gutschilla/plug-session-memcached","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/gutschilla/plug-session-memcached","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gutschilla%2Fplug-session-memcached","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gutschilla%2Fplug-session-memcached/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gutschilla%2Fplug-session-memcached/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gutschilla%2Fplug-session-memcached/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gutschilla","download_url":"https://codeload.github.com/gutschilla/plug-session-memcached/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gutschilla%2Fplug-session-memcached/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280316733,"owners_count":26309993,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-08-01T02:00:48.796Z","updated_at":"2025-10-21T18:41:25.533Z","avatar_url":"https://github.com/gutschilla.png","language":"Elixir","funding_links":[],"categories":["Framework Components"],"sub_categories":[],"readme":"Plug.Session.MEMCACHED\n======================\nA  memcached session store for Elixir's plug. \n\n## Description\n\nProvides the application :plug_session_memcached to be \nincluded in your app. This will create connection to \na memcached server instance. Then, you may use the plug\n`Plug.Session.MEMCACHED`, presumably in a Phoenix endpoint.\n\n## Support\nI use it in conjunction with the great [Phoenix Framework](https://github.com/phoenixframework/phoenix). If you encounter any issues, I'll be glad if you gave me notice.\n\n## Synopsis\nAdd these to your project's `mix.exs`:\nAdding both `:lager` and `:corman` to your `applications` section is required to make thing work if you plan to create a release with the great [exrm](https://github.com/bitwalker/exrm) tool. Also make sure to add the plug to `included_applications`.\n\n```elixir\n# will create a mcd connection to memcached as :memcached_sessions\ndef application do\n  [\n    ...\n    applications: [\n        ...\n       :lager, :corman # \u003c-- add these both (mcd needs them)\n    ],\n    included_applications: [\n        :plug_session_memcached # \u003c--- add this entry\n    ]\n  ]\nend\n\n# add dependency\ndefp deps do\n  [\n    ...\n    {:plug_session_memcached, \"~\u003e 0.3.3\" }, # \u003c-- add this entry\n    {:mcd, github: \"EchoTeam/mcd\"}          # \u003c-- and this one \n  ]\nend\n```\n\nYou may want to alter the standard memcached host/port in your `config.exs` (or `dev.exs` or `prod.exs`). If no config is given, host `127.0.0.1` and port `11211` is used:\n```elixir\n# be sure to use a binary for the host the underlying memcached connector is written in Erlang)\n# server: [ \u003chost_binary\u003e, \u003cport_integer\u003e ]\nconfig :plug_session_memcached,\n  server: [ '127.0.0.1', 11211 ]\n```\n\nBe sure to manually include :mcd as hex won't fetch github dependencies\nautomatically for you. At some point I might switch to tsharju's\n:memcache_client which should do the same.\n\nThen use the plug\n```elixir\nplug Plug.Session,\n  store: :memcached,\n  key: \"_my_app_key\", # use a proper value \n  table: :memcached_sessions, # \u003c-- this on is hard coded into the plug\n  signing_salt: \"123456\",   # use a proper value\n  encryption_salt: \"654321\" # use a proper value\n```\n\nIn phoenix (version 1.0 and above), add the lines above to your `lib/\u003cyourapp\u003e/endpoint.ex`. For an example, see [endpoint.ex in my skeleton app repo](https://github.com/gutschilla/phoenix-skeleton/blob/master/lib/skeleton/endpoint.ex)\n\n## Motivation: Why Memcached when there's an ETS or Cookie store?\nA short discussion: I am probably wrong. \n\nI am using memcached for session storage for over a decade now in conjunction with many languages and web frameworks. And it just works great:\n\n- for me, memcached is battle-proven. Not a single issue in a decade\n- support for memcached server clusters (mcd apparently doesn't support this)\n- 1MB of session storage (default memcached bucket size) as long `:erlang.term_to_binary(\u003cyour_session_data\u003e)` fits in a megabyte\n- no need for a distributed erlang setup in a load-balanced scenario: sessions are like a database on a single-purpose machine.\n\n### Downside of Cookies\nWhile it's so great and simple to store session data in the cookie\nitself, it has some downsides:\n\nEven when the cookie is encrypted and signed, there is still some information \nabout the size of information stored in it.\n\nApart from changing your session key there's no easy way to invalidate a certain\nsession cookie. For example: A user logs in and you assign the value \"user_id\",\n\u003cuser_id\u003e to your session data. Someone could record that cookie and simply re-use it. \n\nIMHO the server should be the single source of truth for login states.\n\n### ETS\nPlug.Session.MEMCACHED.ETS solves the problem of cookies by only storing a\nsession id in the cookie. But it's hard to access from outside of your App and \nif your app needs to restart all your session data is lost which doesn't come in\nhandy in development or production (unless hot code reloading is your cup of tea).\n\n### DETS\nYeah, would be a nice option. But I like session data to be in-memory. When the\nserver crashes session data is gone anyways.\n\n## So Memcached is best?\nCertainly not for all purposes, but for mine. Pro: memcached is fast. I still\nhave to compare it against ETS (which I assume to be faster as one can spare the\nTCP overhead) but for general purpose it's very fast and should not be a\nbottleneck.\n\nMemcached service doesn't go away with your application. A thing that certainly\noften happens in development. If you really want to, you can delete all your\ndata just be restarting memcached. ETS or DETS would give you more options on\nwhat data to delete.\n\nAll in all, storing session data in memcached seems to me like the best fit.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgutschilla%2Fplug-session-memcached","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgutschilla%2Fplug-session-memcached","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgutschilla%2Fplug-session-memcached/lists"}