Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert some more legacy caches to standardise cache container #14487

Closed
wants to merge 2 commits into from

Conversation

seamuslee001
Copy link
Contributor

Overview

This converts some more legacy caches to Civi::cache containers

Before

The current status. Please provide screenshots or gifs (LICEcap, SilentCast) where appropriate.

After

What has been changed. Please provide screenshots or gifs (LICEcap, SilentCast) where appropriate.

ping @totten @eileenmcnaughton

@civibot
Copy link

civibot bot commented Jun 9, 2019

(Standard links)

@civibot civibot bot added the master label Jun 9, 2019
@seamuslee001
Copy link
Contributor Author

Jenkins re test this please

1 similar comment
@seamuslee001
Copy link
Contributor Author

Jenkins re test this please

@@ -688,7 +688,8 @@ public static function retrieve(&$params, &$defaults) {
*/
public static function setIsActive($id, $is_active) {
// note this also resets any ACL cache
CRM_Core_BAO_Cache::deleteGroup('contact fields');
$cache = Civi::cache('fields');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or simply

-  CRM_Core_BAO_Cache::deleteGroup('contact fields');
+  Civi::cache('fields')->flush();

@@ -254,7 +254,8 @@ public static function formRule($params) {
*/
public function postProcess() {
// note this also resets any ACL cache
CRM_Core_BAO_Cache::deleteGroup('contact fields');
$cache = Civi::cache('fields');
$cache->flush();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above


//CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
CRM_Core_BAO_Cache::deleteGroup('navigation');
$navigationCache = Civi::cache('navigation');
$navigationCache->flush();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..same

@@ -1321,9 +1321,10 @@ public static function importableFields(

$fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

$fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields) ?: Civi::cache('fields')->get($cacheKeyString);

@@ -259,7 +259,8 @@ public static function retrieve(&$params, &$defaults) {
*/
public static function setIsActive($id, $is_active) {
// reset the cache
CRM_Core_BAO_Cache::deleteGroup('contact fields');
$cache = Civi::cache('fields');
$cache->flush();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@seamuslee001
Copy link
Contributor Author

thanks @monishdeb i have updated now to hopefully be more streamlined in the code

@monishdeb
Copy link
Member

Nice, from code/style POV I am happy with the patch. Waiting for @totten @eileenmcnaughton for their feedback :)

@@ -296,7 +296,7 @@ public function buildPrevNextCache($sort) {

if (Civi::service('prevnext') instanceof CRM_Core_PrevNextCache_Sql) {
// SQL-backed prevnext cache uses an extra record for pruning the cache.
CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
Civi::cache('prevNextCache')->set($cacheKey, $cacheKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@totten agreed that the effect of

Civi::cache('prevNextCache')->set($cacheKey, $cacheKey);

is a clumsy way of saying


Civi::cache('prevNextCache')->set($cacheKey,  TRUE);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear - I support setting the value in the same way it was set before. But Eileen had a question about whether it was meaningful to do set($cacheKey,$cacheKey), and (conceptually) these could be the same (although I'd make no assumption that they're actually equivalent in practice).

Also, note that CRM_Core_BAO_PrevNextCache::cleanupCache() specifically relies on this cache being stored in SQL. I'd recommend skeptical eye about using a cache-backend that is dynamically-chosen (as in prevNextCache' => 'CiviCRM Search PrevNextCache' ... 'type' => ['*memory*', 'SqlGroup', 'ArrayCache'] in Container.php below) when there are hard-coded bits that assume this cache is SQL-backed...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@totten good point have just pushed up change to ensure prevNextCache is sql Backed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@totten should CRM_Core_BAO_PrevNextCache:::cleanupCache() be aware of the backed provider of prev next service?

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 needs a rebase

Streamline caches calls as per Monish's comments

Split prevNextCache out on its own as it needs to be SQLbacked all the time for the moment whilst clearing is hard coded
@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton rebased now

@eileenmcnaughton
Copy link
Contributor

@totten still hoping you will review this

@seamuslee001
Copy link
Contributor Author

following a chat with @totten i have now split this PR up into separate ones for each cache group

#14580 PrevNextCache
#14581 Navigation
#14582 Custom Data
#14583 contact fields
#14584 contact groups

I have left some notes on what reviewers should be looking at when reviewing. Hopefully split up they might be easier to review

ping @monishdeb @mattwire

@seamuslee001
Copy link
Contributor Author

closing this as it has been addressed via other PRs

@seamuslee001 seamuslee001 deleted the convert_caches branch July 22, 2019 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants