Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NotificationStorage.php
Go to the documentation of this file.
1 <?php
7 
11 
13 {
14  const UPDATE_CUSTOMER_SESSION = 'update_customer_session';
15 
19  private $cache;
20 
24  private $serializer;
25 
31  public function __construct(
32  FrontendInterface $cache,
33  SerializerInterface $serializer = null
34  ) {
35  $this->cache = $cache;
36  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
37  }
38 
46  public function add($notificationType, $customerId)
47  {
48  $this->cache->save(
49  $this->serializer->serialize([
50  'customer_id' => $customerId,
51  'notification_type' => $notificationType
52  ]),
53  $this->getCacheKey($notificationType, $customerId)
54  );
55  }
56 
64  public function isExists($notificationType, $customerId)
65  {
66  return $this->cache->test($this->getCacheKey($notificationType, $customerId));
67  }
68 
76  public function remove($notificationType, $customerId)
77  {
78  $this->cache->remove($this->getCacheKey($notificationType, $customerId));
79  }
80 
88  private function getCacheKey($notificationType, $customerId)
89  {
90  return 'notification_' . $notificationType . '_' . $customerId;
91  }
92 }
__construct(FrontendInterface $cache, SerializerInterface $serializer=null)