{"id":15286158,"url":"https://github.com/yanick/dancer-plugin-cache-chi","last_synced_at":"2025-04-13T03:08:18.194Z","repository":{"id":56835709,"uuid":"1489723","full_name":"yanick/Dancer-Plugin-Cache-CHI","owner":"yanick","description":"Dancer plugin to cache response content (and anything else)","archived":false,"fork":false,"pushed_at":"2018-03-04T17:24:55.000Z","size":95,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"releases","last_synced_at":"2025-04-13T03:08:11.337Z","etag":null,"topics":["cache","dancer","perl"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yanick.png","metadata":{"files":{"readme":"README.mkdn","changelog":"Changes","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":"2011-03-17T00:39:57.000Z","updated_at":"2023-08-17T01:07:24.000Z","dependencies_parsed_at":"2022-09-07T07:10:33.773Z","dependency_job_id":null,"html_url":"https://github.com/yanick/Dancer-Plugin-Cache-CHI","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2FDancer-Plugin-Cache-CHI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2FDancer-Plugin-Cache-CHI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2FDancer-Plugin-Cache-CHI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanick%2FDancer-Plugin-Cache-CHI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanick","download_url":"https://codeload.github.com/yanick/Dancer-Plugin-Cache-CHI/tar.gz/refs/heads/releases","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657918,"owners_count":21140846,"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":["cache","dancer","perl"],"created_at":"2024-09-30T15:10:48.139Z","updated_at":"2025-04-13T03:08:18.170Z","avatar_url":"https://github.com/yanick.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/yanick/Dancer-Plugin-Cache-CHI.svg?branch=master)](https://travis-ci.org/yanick/Dancer-Plugin-Cache-CHI)\n[![AppVeyor Status](https://ci.appveyor.com/api/projects/status/github/yanick/Dancer-Plugin-Cache-CHI?branch=master\u0026svg=true)](https://ci.appveyor.com/project/yanick/Dancer-Plugin-Cache-CHI)\n\n# NAME\n\nDancer::Plugin::Cache::CHI - Dancer plugin to cache response content (and anything else)\n\n# VERSION\n\nversion 1.5.0\n\n# SYNOPSIS\n\nIn your configuration:\n\n```\nplugins:\n    'Cache::CHI':\n        driver: Memory\n        global: 1\n```\n\nIn your application:\n\n```perl\nuse Dancer ':syntax';\nuse Dancer::Plugin::Cache::CHI;\n\n# caching pages' response\n\ncheck_page_cache;\n\nget '/cache_me' =\u003e sub {\n    cache_page template 'foo';\n};\n\n# using the helper functions\n\nget '/clear' =\u003e sub {\n    cache_clear;\n};\n\nput '/stash' =\u003e sub {\n    cache_set secret_stash =\u003e request-\u003ebody;\n};\n\nget '/stash' =\u003e sub {\n    return cache_get 'secret_stash';\n};\n\ndel '/stash' =\u003e {\n    return cache_remove 'secret_stash';\n};\n\n# using the cache directly\n\nget '/something' =\u003e sub {\n    my $thingy = cache-\u003ecompute( 'thingy', sub { compute_thingy() } );\n\n    return template 'foo' =\u003e { thingy =\u003e $thingy };\n};\n```\n\n# DESCRIPTION\n\nThis plugin provides Dancer with an interface to a [CHI](https://metacpan.org/pod/CHI) cache. Also, it\nincludes a mechanism to easily cache the response of routes.\n\n# CONFIGURATION\n\nUnrecognized configuration elements are passed directly to the [CHI](https://metacpan.org/pod/CHI) object's\nconstructor. For example, the configuration given in the [\"SYNOPSIS\"](#synopsis)\nwill create a cache object equivalent to\n\n```perl\n$cache = CHI-\u003enew( driver =\u003e 'Memory', global =\u003e 1, );\n```\n\n## honor\\_no\\_cache\n\nIf the parameter '`honor_no_cache`' is set to true, a request with the http\nheader '`Cache-Control`' or '`Pragma`' set to '_no-cache_' will ignore any\ncontent cached via '`cache_page`' and will have the page regenerated anew.\n\n# KEYWORDS\n\n## cache\n\nReturns the [CHI](https://metacpan.org/pod/CHI) cache object.\n\n## cache $namespace, \\\\%args\n\n[CHI](https://metacpan.org/pod/CHI) only allows one namespace per object. But you can create more caches by\nusing _cache $namespace, \\\\%args_. The new cache uses the arguments as defined in\nthe configuration, which values can be overriden by the optional arguments\n(which are only used on the first invocation of the namespace).\n\n```perl\nget '/memory' =\u003e sub {\n    cache('elephant')-\u003eget( 'stuff' );\n};\n\nget '/goldfish' =\u003e sub {\n    cache( 'goldfish' =\u003e { expires_in =\u003e 300 } )-\u003eget( 'stuff' );\n};\n```\n\nNote that all the other keywords (`cache_page`, `cache_set`, etc) will still\nuse the main cache object.\n\n## check\\_page\\_cache\n\nIf invoked, returns the cached response of a route, if available.\n\nThe `path_info` attribute of the request is used as the key for the route,\nso the same route requested with different parameters will yield the same\ncached content. Caveat emptor.\n\n## cache\\_page($content, $expiration)\n\nCaches the _$content_ to be served to subsequent requests.\nThe headers and http status of the response are also cached.\n\nThe _$expiration_ parameter is optional.\n\n## cache\\_page\\_key\n\nReturns the cache key used by '`cache_page`'. Defaults to\nto the request's _path\\_info_, but can be modified via\n_cache\\_page\\_key\\_generator_.\n\n## cache\\_page\\_key\\_generator( \\\\\u0026sub )\n\nSets the function that generates the cache key for _cache\\_page_.\n\nFor example, to have the key contains both information about the request's\nhostname and path\\_info (useful to deal with multi-machine applications):\n\n```perl\ncache_page_key_generator sub {\n    return join ':', request()-\u003ehost, request()-\u003epath_info;\n};\n```\n\n## cache\\_set, cache\\_get, cache\\_remove, cache\\_clear, cache\\_compute\n\nShortcut to the cache's object methods.\n\n```perl\nget '/cache/:attr/:value' =\u003e sub {\n    # equivalent to cache-\u003eset( ... );\n    cache_set $params-\u003e{attr} =\u003e $params-\u003e{value};\n};\n```\n\nSee the [CHI](https://metacpan.org/pod/CHI) documentation for further info on these methods.\n\n# HOOKS\n\n## before\\_create\\_cache\n\nCalled before the creation of the cache, which is lazily done upon\nits first use.\n\nUseful, for example, to change the cache's configuration at run time:\n\n```perl\nuse Sys::Hostname;\n\n# set the namespace to the current hostname\nhook before_create_cache =\u003e sub {\n    config-\u003e{plugins}{'Cache::CHI'}{namespace} = hostname;\n};\n```\n\n# SEE ALSO\n\nDancer Web Framework - [Dancer](https://metacpan.org/pod/Dancer)\n\n[CHI](https://metacpan.org/pod/CHI)\n\n[Dancer::Plugin::Memcached](https://metacpan.org/pod/Dancer::Plugin::Memcached) - plugin that heavily inspired this one.\n\n[Dancer2::Plugin::Cache::CHI](https://metacpan.org/pod/Dancer2::Plugin::Cache::CHI) - Dancer2 incarnation of this plugin.\n\n# AUTHOR\n\nYanick Champoux \u003cyanick@cpan.org\u003e [![endorse](http://api.coderwall.com/yanick/endorsecount.png)](http://coderwall.com/yanick)\n\n# COPYRIGHT AND LICENSE\n\nThis software is copyright (c) 2018, 2013, 2012, 2011 by Yanick Champoux.\n\nThis is free software; you can redistribute it and/or modify it under\nthe same terms as the Perl 5 programming language system itself.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanick%2Fdancer-plugin-cache-chi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanick%2Fdancer-plugin-cache-chi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanick%2Fdancer-plugin-cache-chi/lists"}