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

Add in Deprecation warnings on Cache functons #14828

Merged
merged 2 commits into from
Jul 15, 2019

Conversation

seamuslee001
Copy link
Contributor

@seamuslee001 seamuslee001 commented Jul 15, 2019

Overview

This adds deprecation warning notices on these functions as they aren't used by Core now

The following functions are deprected

CRM_Core_BAO_Cache::setItem
CRM_Core_BAO_Cache::getItem
CRM_Core_BAO_Cache::getItems
CRM_Core_BAO_Cache::deleteGroup

Developers shoud instead use something like the following instead

Civi::cache()->set()
CIvi::cache()->get()
Civi::cache()->flush()

If a developer wants to have their own Cache Group which might be useful if you are wanting to manage your cached data separate to the rest of data in a short cache then the following should be added in your extension.php file

/**
 * Implements hook_civicrm_container().
 */
function extensionshortname_civicrm_container(\Symfony\Component\DependencyInjection\ContainerBuilder $container) {
  $container->setDefinition("cache.{groupname}", new Symfony\Component\DependencyInjection\Definition(
    'CRM_Utils_Cache_Interface',
    [
      [
        'name' => '{cache group name}',
        'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
        'withArray' => 'fast',
      ],
    ]
  ))->setFactory('CRM_Utils_Cache::create');
}

Then in your code use the following style of code

Civi::cache(<groupname>)->set()
Civi::cache(<groupname>)->get()

For more read https://docs.civicrm.org/dev/en/latest/framework/cache/

Before

No Warning

After

Warning

ping @eileenmcnaughton

@civibot
Copy link

civibot bot commented Jul 15, 2019

(Standard links)

@civibot civibot bot added the master label Jul 15, 2019
@eileenmcnaughton
Copy link
Contributor

@seamuslee001 guess we'd better stop testing it :-)

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton i have updated the tests to be most appropriate i think

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 I'm ok with merging this if it passes but can you update the summary to list what is deprecated & what people should do instead for the release notes?

@seamuslee001
Copy link
Contributor Author

done @eileenmcnaughton

@seamuslee001 seamuslee001 merged commit 9c68f97 into civicrm:master Jul 15, 2019
@seamuslee001 seamuslee001 deleted the deprecation_notices branch July 15, 2019 22:51
@eileenmcnaughton
Copy link
Contributor

@seamuslee001 thanks - I'll add a link to https://docs.civicrm.org/dev/en/latest/framework/cache/ above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants