{"id":16049926,"url":"https://github.com/mitogh/on-cache-please","last_synced_at":"2026-05-17T11:30:18.019Z","repository":{"id":57017692,"uuid":"44920110","full_name":"mitogh/On-Cache-Please","owner":"mitogh","description":":floppy_disk: WordPress - Add automatic cache on requests using the Transients API","archived":false,"fork":false,"pushed_at":"2016-01-16T21:24:35.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-02T15:49:58.134Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitogh.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}},"created_at":"2015-10-25T17:09:53.000Z","updated_at":"2016-01-16T21:23:26.000Z","dependencies_parsed_at":"2022-08-22T12:00:47.208Z","dependency_job_id":null,"html_url":"https://github.com/mitogh/On-Cache-Please","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/mitogh%2FOn-Cache-Please","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitogh%2FOn-Cache-Please/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitogh%2FOn-Cache-Please/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitogh%2FOn-Cache-Please/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitogh","download_url":"https://codeload.github.com/mitogh/On-Cache-Please/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240122574,"owners_count":19751142,"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-10-09T00:41:06.383Z","updated_at":"2026-05-17T11:30:17.974Z","avatar_url":"https://github.com/mitogh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# On Cache Please [![Build Status](https://travis-ci.org/mitogh/On-Cache-Please.svg?branch=master)](https://travis-ci.org/mitogh/On-Cache-Please)\n\n\u003e Because programmers are to lazy to write repeated code, this\n utility automatically storages the data of a callback in a transient to\nfaster access the next time the data is accessed.  \n\n## Description\n\nThis utility can help you to create faster cache storage of expensive\nexternal request or hard work into the DB to faster access the next\ntime, to retrive the value from a cache rather than the function, this\nlibrary make uses of [transient api](https://codex.wordpress.org/Transients_API) to save the\ndata from the requests into the DB.\n\n## Requirements.\n\n- WordPress   \n- PHP 5.4 \u003e=   \n\n## Installation. \n\nThe easiest way to install this library is using composer, in order to\nadd this library as a dependency for your composer file you only need to\nrun in your terminal:\n\n```php\ncomposer require mitogh/on-cache-please\n```\n\nTo retrive the library from [packagist](https://packagist.org/packages/mitogh/on-cache-please). This will\nadd the on-cache-please library as a dependency in your `composer.json`\nfile.\n\nThe other way is directly include the file: \n\n```php\ninclude 'On-Cache-Please/src/OnCache.php';\n```\n\nInto your `functions.php` file in your theme or in your plugin.\n\n## Methods and Properties\n\nHere are listed only the public methods that are available to be used\nfrom the outside of the library.\n\n### OnCache::please\n\nThis static method is the public way to storaged the data from a\nfunction in a transient by a determined amount of time in order to\ndecrease the number of request and download time.\n\n**Parameters**  \n\nYou can pass an `array` of arguments to the method `please` in order to\nupdate some default values and some required params as well.\n\n- `name` *(string)* - required. This is a required param since we need a value to\nidentify the transient, where the data is going to be stored.\n- `callback` *(string|function)* - required. The function or name of the\n  function to execute, in this function you can do expensive things like\nan http external request or a instagram API call, just make sure to\nreturn the data you want to save on the cache, the returned value will\nbe storead in the transient.\n- `duration` *(int)* - optional. 1 hour by default. This value can be any\n  integer number and represents the life of the transient in seconds\nbefore execute the `callback` again and update the transient, there are\nfew [few already defined](https://codex.wordpress.org/Transients_API#Using_Time_Constants).\nconstants that migh help you.\n\n**Example**\n\nIn this example we retrieve the data from `http://codepen.io/jobs.json`\nand store the result in a transient that has a duration (by default of 1\nhour), so the next hour we are going to have the latest updated data\nwiouth having to make a request every time the page is loaded.   \n\nLibrary installed via `composer.json`  \n\n```php\ninclude './vendor/autoload.php';\n$args = array(\n    'name' =\u003e 'codepen_jobs',\n\t'callback' =\u003e function(){\n\t\t$url = 'http://codepen.io/jobs.json';\n\t\treturn wp_remote_retrieve_body( wp_remote_get( $url ) );\n\t},\n);\n$jobs = mitogh\\OnCache::please( $args );\n```\n\nLibrary installed manually:  \n\n```php\ninclude './On-Cache-Please/src/OnCache.php';\n$args = array(\n    'name' =\u003e 'codepen_jobs',\n\t'callback' =\u003e function(){\n\t\t$url = 'http://codepen.io/jobs.json';\n\t\treturn wp_remote_retrieve_body( wp_remote_get( $url ) );\n\t},\n);\n$jobs = mitogh\\OnCache::please( $args );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitogh%2Fon-cache-please","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitogh%2Fon-cache-please","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitogh%2Fon-cache-please/lists"}