Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for wp_cache_add() and wp_cache_delete()
This sniff checks that any direct database calls are accompanied by caching. Up to now, only `wp_cache_get()` and `wp_cache_set()` were checked for. The sniff requires that these two functions both be called in order for the database call to pass. But it is possible to use `wp_cache_add()` to add to the cache instead of `wp_cache_set()`, so I have updated the sniff to provide for this, checking for either set or add, but either must still be used along with get. There are also cases, such as when a complex `UPDATE` query must be run with `$wpdb->query()`, where this form of get-set/add caching does not apply. In such a case, it is necessary to call `wp_cache_delete()` instead. So I have updated the sniff to allow for the `query()` method to pass when accompanied by a cache delete **or** when accompanied by cache get and set/add. In the process I’ve realized that whenever the `update()`, `delete()`, or `replace()` methods are used, there is also a need to clear the cache. So I have moved these to the list of cacheable functions, leaving only `insert()` as non-cacheable. Like `query()`, these functions will pass the caching part of the sniff if they are accompanied by a cache delete, or if they are accompanied by a cache get and add/set. The reason that the latter is also allowed, is for the case when the cache make be an array of things, only one of which is being updated/deleted. In the process, I found out that there was a method in the list, `execute()` which does not exist as part of `$wpdb`. I don’t know where it came from, but I’ve removed it from the list and added `delete()`, which was previously absent. For those who care, I think that I might even have squeaked a small performance boost out of the sniff in the process. Fixes #397
- Loading branch information