You are here

public function CampaignMonitor::removeSubscriberFromCache in Campaign Monitor 8

Remove subscribers from local cache. This forces the data to be fetched from Campaign Monitor at the next request. This function should be used in connection with updating subscriber information.

Parameters

mixed $listId: The unique Campaign Monitor list ID.

mixed $email: The e-mail address to be removed from cache.

3 calls to CampaignMonitor::removeSubscriberFromCache()
CampaignMonitor::subscribe in src/CampaignMonitor.php
Subscribe a user to a given list, with information entered. If the user is already subscribed to the list, her/his information will be updated with the new values.
CampaignMonitor::unsubscribe in src/CampaignMonitor.php
Unsubscribe a given user, identified by e-mail address, from a given list.
CampaignMonitor::updateSubscriberEmail in src/CampaignMonitor.php
Updates the subscriber e-mail address for a given list.

File

src/CampaignMonitor.php, line 812
Implementation of the CampaignMonitor class, which is a wrapper class for Campaign Monitor v3 API. It's implemented as a Singleton class and instances are created using the account variables and the static function getConnector(). An example:.

Class

CampaignMonitor

Namespace

Drupal\campaignmonitor

Code

public function removeSubscriberFromCache($listId, $email) {
  if (($cache = \Drupal::cache()
    ->get('campaignmonitor_subscribers')) && !empty($cache->data)) {

    // Cache information found.
    $this->subscribers = $cache->data;
    if (isset($this->subscribers[$listId . $email])) {

      // Subscriber found in the cache, so remove it.
      unset($this->subscribers[$listId . $email]);
      \Drupal::cache()
        ->set('campaignmonitor_subscribers', $this->subscribers, $this
        ->getCacheTimeout());
    }
  }
}