{"id":27629564,"url":"https://github.com/markjaquith/wp-tlc-transients","last_synced_at":"2025-10-04T18:26:55.298Z","repository":{"id":62524204,"uuid":"2330305","full_name":"markjaquith/WP-TLC-Transients","owner":"markjaquith","description":null,"archived":false,"fork":false,"pushed_at":"2020-10-06T17:29:13.000Z","size":250,"stargazers_count":342,"open_issues_count":14,"forks_count":37,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-09-28T04:35:39.493Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markjaquith.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-09-05T19:53:24.000Z","updated_at":"2025-08-05T02:27:47.000Z","dependencies_parsed_at":"2022-11-02T15:30:51.688Z","dependency_job_id":null,"html_url":"https://github.com/markjaquith/WP-TLC-Transients","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/markjaquith/WP-TLC-Transients","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markjaquith%2FWP-TLC-Transients","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markjaquith%2FWP-TLC-Transients/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markjaquith%2FWP-TLC-Transients/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markjaquith%2FWP-TLC-Transients/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markjaquith","download_url":"https://codeload.github.com/markjaquith/WP-TLC-Transients/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markjaquith%2FWP-TLC-Transients/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278354525,"owners_count":25973375,"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-04T02:00:05.491Z","response_time":63,"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":"2025-04-23T15:26:52.568Z","updated_at":"2025-10-04T18:26:55.265Z","avatar_url":"https://github.com/markjaquith.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TLC Transients\n\nA WordPress transients interface with support for soft-expiration (use old content until new content is available), background updating of the transients (without having to wait for a cron job), and a chainable syntax that allows for one liners.\n\n## License\n\nTLC Transients is licensed under the GPL, version 2.0 or any later version. See `LICENSE`.\n\n## Examples\n\nIn this simple example, we're defining a feed-fetching callback, and then using `tlc_transient` with a chain to point to that callback and use it, all in one line. Note that since we haven't used `background_only()`, the initial load of this **will** cause the page to pause.\n\n```php\n\u003c?php\n// Define your callback (other examples use this)\nfunction my_callback() {\n\treturn wp_remote_retrieve_body(\n\t\twp_remote_get( 'http://example.com/feed.xml', array( 'timeout' =\u003e 30 ) )\n\t);\n}\n\n// Grab that feed\necho tlc_transient( 'example-feed' )\n\t-\u003eupdates_with( 'my_callback' )\n\t-\u003eexpires_in( 300 )\n\t-\u003eget();\n?\u003e\n```\nThis time, we'll set `background_only()` in the chain. This means that if there has been a hard cache flush, or this is the first-ever request, it will return false. So your code will have to be written to gracefully degrade if the feed isn't yet available. This, of course, triggers a background update. And once it is available, it will start returning the content.\n\n```php\n\u003c?php\necho tlc_transient( 'example-feed' )\n\t-\u003eupdates_with( 'my_callback' )\n\t-\u003eexpires_in( 300 )\n\t-\u003ebackground_only()\n\t-\u003eget();\n?\u003e\n```\n\nWe don't have to chain, of course.\n\n```php\n\u003c?php\n$t = tlc_transient( 'example-feed' );\nif ( true ) {\n\t$t-\u003eupdates_with( 'my_callback' );\n} else {\n\t$t-\u003eupdates_with( 'some_other_callback' );\n}\n\n$t-\u003eexpires_in( 300 );\necho $t-\u003eget();\n?\u003e\n```\nWe can even pass parameters to our callback.\n\n```php\n\u003c?php\n// Define your callback\nfunction my_callback_with_param( $param ) {\n\treturn str_replace(\n\t\t'foo',\n\t\t$param,\n\t\twp_remote_retrieve_body( wp_remote_get( 'http://example.com/feed.xml', array( 'timeout' =\u003e 30 ) ) ),\n\t);\n}\n\n// Grab that feed\necho tlc_transient( 'example-feed' )\n\t-\u003eupdates_with( 'my_callback_with_param', array( 'bar' ) )\n\t-\u003eexpires_in( 300 )\n\t-\u003ebackground_only()\n\t-\u003eget();\n?\u003e\n```\n\n## Notes\n\n### Context\n\nIt should be noted that when a callback runs asynchronously, you are not in control of context. The context that existed when you registered the callback has no bearing on the context when the callback is actually run. So if there is **anything** that you're assuming in your callback function (whether a certain user being current, a certain post having been queried, etc), you must rewrite your calllback function so that these assumptions are not made, and instead pass in this context in the form of parameters, which your callback then uses to recreate your desired context.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkjaquith%2Fwp-tlc-transients","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkjaquith%2Fwp-tlc-transients","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkjaquith%2Fwp-tlc-transients/lists"}