{"id":16409595,"url":"https://github.com/revertit/mybb-rt_extendedcache","last_synced_at":"2025-02-24T02:26:17.365Z","repository":{"id":152777325,"uuid":"627114272","full_name":"RevertIT/mybb-rt_extendedcache","owner":"RevertIT","description":"RT Extended Cache is a plugin which extends native MyBB cache handler with new functionalities to ease the users and developers work. ","archived":false,"fork":false,"pushed_at":"2024-02-13T00:00:31.000Z","size":44,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-06T00:42:12.990Z","etag":null,"topics":["cache-control","mybb-plugin","php8"],"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/RevertIT.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-04-12T20:13:56.000Z","updated_at":"2024-05-17T05:47:01.000Z","dependencies_parsed_at":"2023-07-07T16:15:43.758Z","dependency_job_id":null,"html_url":"https://github.com/RevertIT/mybb-rt_extendedcache","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RevertIT%2Fmybb-rt_extendedcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RevertIT%2Fmybb-rt_extendedcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RevertIT%2Fmybb-rt_extendedcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RevertIT%2Fmybb-rt_extendedcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RevertIT","download_url":"https://codeload.github.com/RevertIT/mybb-rt_extendedcache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240405439,"owners_count":19796190,"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-control","mybb-plugin","php8"],"created_at":"2024-10-11T06:20:32.175Z","updated_at":"2025-02-24T02:26:17.335Z","avatar_url":"https://github.com/RevertIT.png","language":"PHP","readme":"## RT Extended Cache\nRT Extended Cache is a plugin that extends the native MyBB cache handler with additional functionalities to simplify the work of both users and developers. The plugin provides new functions, including auto expiration time for the cache, auto increment and decrement methods, and the ability to cache database queries on the fly.\n\n### Table of contents\n\n1. [❗ Dependencies](#-dependencies)\n2. [📃 Features](#-features)\n3. [➕ Installation](#-installation)\n4. [🔼 Update](#-update)\n5. [📜 Usage](#-usage)\n6. [💡 Feature request](#-feature-request)\n7. [🙏 Questions](#-questions)\n8. [🐞 Bug reports](#-bug-reports)\n\n### ❗ Dependencies\n- MyBB 1.8.x\n- PHP \u003e= 8.0\n\n### 📃 Features\n- Note: RT Caches are stored with custom prefix, so you can't use it to load default caches. For that use MyBB's `$cache`\n- Set auto expiration time to the cache.\n- Auto increment (convenient method for incrementing value).\n- Auto decrement (convenient method for decrementing value).\n- Cache database queries on the fly.\n- Cache remote api requets on the fly.\n\n### ➕ Installation\n- Copy the directories from the plugin inside your root MyBB installation.\n\n### 🔼 Update\n- Copy/paste new files into your MyBB root directory.\n\n## 📜 Usage\n\n### Load RT Cache into plugin/file\nTo load RT Cache into your plugin or file, you should include the following snippet at the top of your plugin or below require `./global.php` if including inside custom file.\n\n- **Load RT Cache inside plugin**\n```php\n\u003c?php\n\nif (!defined(\"IN_MYBB\"))\n{\n    die(\"Direct initialization of this file is not allowed.\");\n}\n\n// START: Include from here\nif (!defined('RT_EXTENDEDCACHE'))\n{\n    define('RT_EXTENDEDCACHE', MYBB_ROOT.'inc/plugins/rt_extendedcache.php');\n}\nrequire_once RT_EXTENDEDCACHE;\n// END: Include from here\n```\n- **Load RT Cache inside custom `customfile.php`**\n```php\n\u003c?php\n\ndefine(\"IN_MYBB\", 1);\ndefine('THIS_SCRIPT', 'customfile.php');\nrequire_once \"./global.php\";\n\n// START: Include from here\nif (!defined('RT_EXTENDEDCACHE'))\n{\n    define('RT_EXTENDEDCACHE', MYBB_ROOT.'inc/plugins/rt_extendedcache.php');\n}\nrequire_once RT_EXTENDEDCACHE;\n// END: Include from here\n```\n\nThen you should include `global $rt_cache` inside your functions or hooks. For example:\n\n```php\nfunction misc_hook()\n{\n    global $rt_cache;\n\n    $rt_cache-\u003eget('some_cache');\n}\n```\n\n### Check version\nTo get plugin version, use the `$rt_cache-\u003eversion`. Here's an example to check in your plugin if theres need for newer version of RT Extended Cache:\n```php\nif ($rt_cache-\u003eversion \u003c 2)\n{\n    // do something\n}\n```\n\n### Set cache\nTo set cache data, use the `set()` method with the cache name, cache data, and optional expiration time in seconds as parameters:\n\n```php\n$rt_cache-\u003eset('cache_name', $data, 3600);\n```\nThe code above will store `$data` in the cache with the key `cache_name` for one hour (3600 seconds).\n\n### Get cache\nTo get cache data, use the `get()` method with the cache name:\n\n```php\n$rt_cache-\u003eget('cache_name');\n```\nThe code above will retrieve `$data` in the cache with the key `cache_name`.\n\n### Delete cache\nThe `delete()` method allows you to delete cache. Here's an example:\n\n```php\n$rt_cache-\u003edelete(\"cache_name\");\n```\n\n### Auto increment\nThe increment() method is a convenient way to increase the value of a cache key. Use it with the key name and the amount to increase the value:\n```php\n// Increment the value by 1\n$new_value = $rt_cache-\u003eincrement('foo_bar');\n\n// Increment the value by 5\n$new_value = $rt_cache-\u003eincrement('foo_bar', 5);\n\n// Delete the cache // Will always return 0\n$new_value = $rt_cache-\u003eincrement('foo_bar', 0);\n```\n\n### Auto decrement\nThe increment() method is a convenient way to decrease the value of a cache key. Use it with the key name and the amount to decrease the value:\n```php\n// Decrement the value by 1\n$new_value = $rt_cache-\u003edecrement('foo_baz');\n\n// Decrement the value by 5\n$new_value = $rt_cache-\u003edecrement('foo_baz', 5);\n\n// Delete the cache\n$new_value = $rt_cache-\u003edecrement('foo_baz', 0);\n```\n\n### Get cached query\nThe `query()` method allows you to cache the results of database queries. Here's an example:\n\n```php\n$uid = 1;\n$user = $rt_cache-\u003equery(\"SELECT * FROM \" . TABLE_PREFIX . \"users WHERE uid = '{$db-\u003eescape_string($uid)}'\")\n                  -\u003ecache('cached_user_data_' . $uid, 3600)\n                  -\u003eexecute();\n```\nThe code above will cache the query and store it with a key `cached_user_data_$uid` for `3600` seconds, after that it will refresh the query and get new data.\n\n### Delete cached query\nThe `delete()` method allows you to delete the query cache with key name. Here's an example:\n\n```php\n$uid = 1;\n$user = $rt_cache-\u003equery(\"SELECT * FROM \" . TABLE_PREFIX . \"users WHERE uid = '{$db-\u003eescape_string($uid)}'\")\n                  -\u003edelete('cached_user_data_' . $uid);\n```\nThe code above will delete the cached query with a key `cached_user_data_$uid`.\n\n### Get cached API request\nThe `api()` method allows you to cache the results of requested API url. Here's an example:\n\n```php\n$user = $rt_cache-\u003eapi(\"https://api-link.com/\")\n                  -\u003ecache('api_data_from', 3600)\n                  -\u003eexecute();\n```\nThe code above will cache the api response and store it with a key `api_data_from` for `3600` seconds, after that it will get new request to api and get new data.\n\n### Delete cached query\nThe `delete()` method allows you to delete the API cache with key name. Here's an example:\n\n```php\n$user = $rt_cache-\u003eapi(\"https://api-link.com/\")\n                  -\u003edelete('api_data_from');\n```\nThe code above will delete the cached api with a key `api_data_from`.\n\n### 💡 Feature request\nOpen a new idea by [clicking here](https://github.com/RevertIT/mybb-rt_extendedcache/discussions/new?category=ideas)\n\n### 🙏 Questions\nOpen a new question by [clicking here](https://github.com/RevertIT/mybb-rt_extendedcache/discussions/new?category=q-a)\n\n### 🐞 Bug reports\nOpen a new bug report by [clicking here](https://github.com/RevertIT/mybb-rt_extendedcache/issues/new)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevertit%2Fmybb-rt_extendedcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frevertit%2Fmybb-rt_extendedcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevertit%2Fmybb-rt_extendedcache/lists"}