{"id":21700688,"url":"https://github.com/marcocesarato/php-cpdo","last_synced_at":"2025-10-10T12:16:50.701Z","repository":{"id":57016311,"uuid":"135810064","full_name":"marcocesarato/PHP-CPDO","owner":"marcocesarato","description":"This package can retrieve PDO query results from cache variables. It extends the base PDO class and override some functions to handle database query execution and store the query results in variables.  The class can also return query results for cached queries for previously executed queries to retrieve the results faster for repeated queries.","archived":false,"fork":false,"pushed_at":"2022-12-16T13:19:46.000Z","size":79,"stargazers_count":4,"open_issues_count":1,"forks_count":4,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-10T12:16:49.867Z","etag":null,"topics":["cache","cachepdo","cpdo","database","memory","pdo","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcocesarato.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":"2018-06-02T10:53:50.000Z","updated_at":"2022-09-24T22:11:47.000Z","dependencies_parsed_at":"2023-01-29T14:01:02.314Z","dependency_job_id":null,"html_url":"https://github.com/marcocesarato/PHP-CPDO","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/marcocesarato/PHP-CPDO","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocesarato%2FPHP-CPDO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocesarato%2FPHP-CPDO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocesarato%2FPHP-CPDO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocesarato%2FPHP-CPDO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcocesarato","download_url":"https://codeload.github.com/marcocesarato/PHP-CPDO/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcocesarato%2FPHP-CPDO/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003899,"owners_count":26083639,"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-10T02:00:06.843Z","response_time":62,"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":["cache","cachepdo","cpdo","database","memory","pdo","php"],"created_at":"2024-11-25T20:16:03.184Z","updated_at":"2025-10-10T12:16:50.685Z","avatar_url":"https://github.com/marcocesarato.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CPDO - Cache PDO Query Class\n\n**Version:** 0.2.3.47 beta\n\n**Github:** https://github.com/marcocesarato/PHP-CPDO \n\n**Author:** Marco Cesarato\n\n## Description\n\nThis package can retrieve PDO query results from cache variables.\n\nIt extends the base PDO class and override some functions to handle database query execution and store the query results in variables.\n\nThe class can also return query results for cached queries for previously executed queries to retrieve the results faster for repeated queries.\n\nIt permit to have cached `SELECT/SHOW/DESCRIBE` queries on Memory (RAM). Then after the execution the cache will be deleted.\n\nCache is cleaned on `INSERT/UPDATE/DELETE/TRUNCATE...` only for the single table.\n\n## What problem this solves\nWhen we call the same query (for example on ORM based system) we retrieve from the database the same data doing the same operation and some time we overload the database server (for example retrieving big data multiple times).\n\nThis class prevent to do the same query on the database, retrieving the data from memory without overload the database server in some cases.\n\n### Requirements\n* PHP\n* Database\n\n## Databases supported (`CPDO::connect`)\n* 4D\n* CUBRID\n* Firebird/Interbase\n* IBM\n* Informix\n* MS SQL Server\n* MySQL\n* ODBC and DB2\n* Oracle\n* PostgreSQL\n* SQLite\n\n## Install\n### Composer\n1. Install composer\n2. Type `composer require marcocesarato/cpdo`\n4. Enjoy\n\n## Usage\n\nYou have to use this class as PDO.\n\nCPDO introduced these new methods:\n\n### Method `connect`\n\nThis feature is a DSN autogeneration and you have to use it instead of the constructor.\n\n#### Usage of `connect`\n\n```php\n$db = CPDO::connect($database_type, $database_name, $database_host = null, $database_user = null, $database_pswd = null);\n```\n\n### Method `getTables`\n\nReturn the names of all database tables as `array`\n\n### Method `backup`\n\nYou can backup **Data** (At the moment no TRIGGERS, VIEWS and EVENTS _if you need it you can request it to the developer_).\nYou can choose if you want the tables you want backup through an `array`.\n\n#### Usage of `backup`\n\n```php\n$db-\u003ebackup($backup_dir, $backup_tables = '*');\n```\n\n## Cache \nYou can disable/enable the cache using the following methods (default is *disabled*):\n```php\n$db-\u003edisableCache();\n$db-\u003eenableCache();\n```\nor\n```php\nCPDOCache::disable();\nCPDOCache::enable();\n```\n\n### Methods available:\n- `void CPDOCache::enable()`  ENABLE Cache\n- `void CPDOCache::disable()` DISABLE Cache\n- `void CPDOCache::populate(array $cache)` Populate cache (see below persistent cache)\n- `array CPDOCache::retrieve()` Retrieve cache (see below persistent cache)\n- `void CPDOCache::addException(string $table_name)` Add not cacheable table\n- `void CPDOCache::addExceptions(array $tables_name)` Add not cacheable tables\n\n## Debugger\nYou can enable/disable the debugger using the following methods (default is *enabled*):\n```php\n$db-\u003eenableDebug();\n$db-\u003edisableDebug();\n```\nor\n```php\nCPDOLogger::enable();\nCPDOLogger::disable();\n```\n\n### Methods available:\n- `void CPDOLogger::enable()`  ENABLE Cache\n- `void CPDOLogger::disable()` DISABLE Cache\n- `array CPDOLogger::getLogs();` Get complete logs (with time of execution and if cache used)\n- `array CPDOLogger::getQueries()` Get all queries requested\n- `int CPDOLogger::getCounter()` Get the counter of queries requested\n- `void CPDOLogger::cleanLogs();` Clean Logs\n\n### Example of complete logs `getLogs()`\n```php\narray (\n  'count' =\u003e 3,\n  'queries' =\u003e \n  array (\n    'SET NAMES \\'utf8\\'' =\u003e \n        array (\n          0 =\u003e \n          array (\n            'time' =\u003e 1530610903,\n            'execution_time' =\u003e 0.000247955322265625,\n            'cached' =\u003e false,\n          ),\n          1 =\u003e \n            array (\n              'time' =\u003e 1530610903,\n              'execution_time' =\u003e 0.000077955322265625,\n              'cached' =\u003e false,\n            ),\n        ),\n    'SELECT id FROM _deleted_records_ WHERE table = \\'settings\\' LIMIT 1' =\u003e \n        array (\n          0 =\u003e \n          array (\n            'time' =\u003e 1530610903,\n            'execution_time' =\u003e 0.00050687789916992188,\n            'cached' =\u003e false,\n          ),\n        ),\n  ),\n)\n```\n\n## (Not recommended) Persistent cache\n*PS: this usage is not recommended!!!*\n\nIf you want a persitent you can use the method `CPDOCache::populate` for populate the cache and `CPDOCache::retrieve` for retrieve the cache.\n\nThanks these methods you could implement a persistent cache system saving the data encoded (with json or serialization) and after restore the cache.\n\nPro:\n- Less database stress\n- Less queries\n\nCons:\n- Could compromise data\n- Could be slower (disk performance/clients connected)\n\n### Example of usage\n```php\n\n// Your loader/includes... =\u003e with require_once('CPDO.php');\n\n$database_cache_path = '/your/cache/path/database.json';\n\n$cache = file_get_contents($database_cache_path);\n$cache = json_decode($cache); // Or unserialize (slower)\nCPDOCache::populate($cache);\nunset($cache);\n\n\n// Your code...\n\n\n$cache = CPDOCache::retrieve();\n$cache = json_encode($cache); // Or serialize (slower)\nfile_put_contents($database_cache_path, $cache);\nunset($cache);\n```\n\n## Methods\n\n\n### CPDO\n\nSame methods of PDO in additions the following:\n\n| Methods      | Parameters                                         | Description                            |\n| ------------ | -------------------------------------------------- | -------------------------------------- |\n| connect      | \t  param $database_type\u003cbr\u003e\t  param null $database_name\u003cbr\u003e\t  param null $database_host\u003cbr\u003e\t  param null $database_user\u003cbr\u003e\t  param null $database_pswd\u003cbr\u003e param null $database_charset\u003cbr\u003e\t  return bool\\|static | Autogeneration of the DSN              |\n| enableDebug  |                                                    | Enable debug                           |\n| disableDebug |                                                    | Disable debug                          |\n| enableCache  |                                                    | Enable cache                           |\n| disableCache |                                                    | Disable cache                          |\n| getTables    | \t  return array\\|bool                              | Get list of database tables            |\n| backup       | \t  param string $tables                            | Backup database tables or just a table |\n| escape       | \t  param string $value                             | Escape variable                        |\n\n### CPDOLogger\n\n| Methods      | Parameters                                         | Description                            |\n| ------------ | -------------------------------------------------- | -------------------------------------- |\n| enable       |                                                    | Enable logs                            |\n| disable      |                                                    | Disable logs                           |\n| isEnabled    | \t  return bool                                     | Return if logs are enabled             |\n| addLog       | \t  param $query\u003cbr\u003e\t  param $time\u003cbr\u003e\t  param $cache | Add new log                            |\n| getLogs      | \t  return array                                    | Get Logs                               |\n| getCounter   | \t  return int                                      | Get Counter                            |\n| getQueries   | \t  return array                                    | Get Counter                            |\n| cleanLogs    |                                                    | Clean Logs                             |\n\n### CPDOCache\n\n| Methods             | Parameters                                         | Description                            |\n| ------------------- | -------------------------------------------------- | -------------------------------------- |\n| disable             |                                                    | Disable cache                          |\n| isEnabled           | \t  return bool                                     | Return if cache is enabled             |\n| populate            | \t  param $mixed\u003cbr\u003e\t  return bool                  | Populate cache                         |\n| retrieve            | \t  return array                                    | Retrieve Cache                         |\n| getExceptions       | \t  return array                                    | Get all excluded tables                |\n| addException        | \t  param $exclude                                  | Add exception                          |\n| addExceptions       | \t  param $exclude                                  | Add exceptions                         |\n| setcache            | \t  param $query\u003cbr\u003e\t  param $value\u003cbr\u003e\t  param null $arg | Set Cache                              |\n| getcache            | \t  param $query\u003cbr\u003e\t  param null $arg\u003cbr\u003e\t  return null | Get Cache                              |\n| deletecache         | \t  param $query                                    | Delete Cache                           |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcocesarato%2Fphp-cpdo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcocesarato%2Fphp-cpdo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcocesarato%2Fphp-cpdo/lists"}