{"id":13776247,"url":"https://github.com/openresty/lua-resty-memcached-shdict","last_synced_at":"2025-07-08T02:36:11.392Z","repository":{"id":136300238,"uuid":"71947955","full_name":"openresty/lua-resty-memcached-shdict","owner":"openresty","description":"Powerful memcached client with a shdict caching layer and many other features","archived":false,"fork":false,"pushed_at":"2019-01-15T05:20:50.000Z","size":12,"stargazers_count":34,"open_issues_count":0,"forks_count":9,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-02-13T20:34:02.162Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openresty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-10-25T23:36:59.000Z","updated_at":"2023-03-02T14:27:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"9ca98ff7-d39f-4f2e-8f9b-dc937f345fb4","html_url":"https://github.com/openresty/lua-resty-memcached-shdict","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-memcached-shdict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-memcached-shdict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-memcached-shdict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Flua-resty-memcached-shdict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openresty","download_url":"https://codeload.github.com/openresty/lua-resty-memcached-shdict/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253551495,"owners_count":21926303,"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":[],"created_at":"2024-08-03T18:00:20.537Z","updated_at":"2025-05-11T10:30:52.427Z","avatar_url":"https://github.com/openresty.png","language":"Lua","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"Name\n====\n\nlua-resty-memcached-shdict - Powerful memcached client with a shdict caching layer and many other features\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Synopsis](#synopsis)\n* [Description](#description)\n* [Caveats](#caveats)\n* [Dependencies](#dependencies)\n* [TODO](#todo)\n* [Author](#author)\n* [Copyright and License](#copyright-and-license)\n* [See Also](#see-also)\n\nStatus\n======\n\nExperimental.\n\nSynopsis\n========\n\n```lua\nlocal shdict_memc = require \"resty.memcached.shdict\"\n\nlocal function dlog(ctx, ...)\n    ngx.log(ngx.DEBUG, \"my app: \", ...)\nend\n\nlocal function error_log(ctx, ...)\n    ngx.log(ngx.ERR, \"my app: \", ...)\nend\n\nlocal function warn(ctx, ...)\n    ngx.log(ngx.WARN, \"my app: \", ...)\nend\n\nlocal memc_fetch, memc_store =\n    shdict_memc.gen_memc_methods{\n        tag = \"my memcached server tag\",\n        debug_logger = dlog,\n        warn_logger = warn,\n        error_logger = error_log,\n\n        locks_shdict_name = \"some_lua_shared_dict_name\",\n\n        shdict_set = meta_shdict_set,  -- generated by lua-resty-shdict-simple or\n                                       -- any other API compatible function factories\n\n        shdict_get = meta_shdict_get,  -- ditto\n\n        disable_shdict = false,  -- optional, default false\n\n        memc_host = \"127.0.0.1\",\n        memc_port = 11211,\n        memc_timeout = 200,  -- in ms\n        memc_conn_pool_size = 5,\n        memc_fetch_retries = 2,  -- optional, default 1\n        memc_fetch_retry_delay = 100, -- in ms, optional, default to 100 (ms)\n\n        memc_conn_max_idle_time = 10 * 1000,  -- in ms, for in-pool connections,\n                                              -- optional, default to nil\n\n        memc_store_retries = 2,  -- optional, default to 1\n        memc_store_retry_delay = 100,  -- in ms, optional, default to 100 (ms)\n\n        store_ttl = 1,  -- in seconds, optional, default to 0 (i.e., never expires)\n    }\n\n-- on hot code paths:\n\nlocal ctx = ngx.ctx\n\n-- in case of failure, can return the stale data with an error message\nlocal data, err = memc_fetch(ctx, key)\n\n-- using the default ttl specified by \"store_ttl\"\nlocal ok = memc_store(ctx, key, value)\n\nok = memc_store(ctx, key, value, ttl)  -- overriding the default ttl\n```\n\nDescription\n===========\n\nThis library provides a powerful memcached client that deliver the following important features:\n\n1. Automatically using shm-based caching layer with OpenResty's [lua_shared_dict](https://github.com/openresty/lua-nginx-module#lua_shared_dict).\nThis local shm cache layer can also be turned off by setting the `disable_shdict` to `true`.\n1. Automatically using server-level (not worker-level) cache locks (based on\n[lua-resty-lock](https://github.com/openresty/lua-resty-lock)) to avoid duplicate and concurrent\nqueries to the memcached server for the same key when it is a cache miss in the local shm cache.\n1. Automatically handles and logs any errors while accessing the Memcached server or `lua_shared_dict`.\n1. Automatically uses connection pools for all the Memcached queries.\n1. Automatically returns stale (or expired) data item in the local shm cache when a cache miss happens\n*and* some other light threads are already querying Memcached and updating the cache for the same key.\n1. Automatically retry querying Memcached when failures happen (like intermittent network issues).\n\nThis library is mostly used for cases that use Memcached or Memcached-compatible servers as the\ndata storage (like Kyoto Tycoon).\n\nAtop this library, the user can further add another per-worker caching layer by employing the\n[lua-resty-lrucache](https://github.com/openresty/lua-resty-lrucache)\nlibrary herself, and/or add asynchronous cache updating mechanism via [ngx.timer.at](https://github.com/openresty/lua-nginx-module#ngxtimerat).\n\nCaveats\n=======\n\n* Unlike the [lua-resty-memcached](https://github.com/openresty/lua-resty-memcached) library,\nthis client does not escape special characters in the key by default. So it is the caller's responsibility\nto avoid using special characters in the keys.\n\n[Back to TOC](#table-of-contents)\n\nDependencies\n============\n\nThis library depends on the following Lua libraries:\n\n* [lua-resty-memcached](https://github.com/openresty/lua-resty-memcached)\n* [lua-resty-lock](https://github.com/openresty/lua-resty-lock)\n* [lua-resty-shdict-simple](https://github.com/openresty/lua-resty-shdict-simple)\n\n[Back to TOC](#table-of-contents)\n\nTODO\n====\n\n* Add a test suite under `t/`.\n\n[Back to TOC](#table-of-contents)\n\nAuthor\n======\n\nYichun \"agentzh\" Zhang (章亦春) \u003cagentzh@gmail.com\u003e, CloudFlare Inc.\n\n[Back to TOC](#table-of-contents)\n\nCopyright and License\n=====================\n\nThis module is licensed under the BSD license.\n\nCopyright (C) 2016, by CloudFlare Inc.\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n[Back to TOC](#table-of-contents)\n\nSee Also\n========\n\n* [lua-resty-shdict-simple](https://github.com/openresty/lua-resty-shdict-simple)\n* [lua-resty-lrucache](https://github.com/openresty/lua-resty-lrucache)\n* [lua-resty-memcached](https://github.com/openresty/lua-resty-memcached)\n* [lua_shared_dict](https://github.com/openresty/lua-nginx-module#lua_shared_dict)\n\n[Back to TOC](#table-of-contents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Flua-resty-memcached-shdict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenresty%2Flua-resty-memcached-shdict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Flua-resty-memcached-shdict/lists"}