Code Duplication    Length = 16-21 lines in 14 locations

eZ/Publish/Core/Persistence/Cache/ContentLanguageHandler.php 1 location

@@ 46-61 (lines=16) @@
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function load($id)
47
    {
48
        $cacheItem = $this->cache->getItem('ez-language-' . $id);
49
        if ($cacheItem->isHit()) {
50
            return $cacheItem->get();
51
        }
52
53
        $this->logger->logCall(__METHOD__, array('language' => $id));
54
        $language = $this->persistenceHandler->contentLanguageHandler()->load($id);
55
56
        $cacheItem->set($language);
57
        $cacheItem->tag('language-' . $language->id);
58
        $this->cache->save($cacheItem);
59
60
        return $language;
61
    }
62
63
    /**
64
     * {@inheritdoc}

eZ/Publish/Core/Persistence/Cache/ContentTypeHandler.php 3 locations

@@ 67-82 (lines=16) @@
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function loadGroup($groupId)
68
    {
69
        $cacheItem = $this->cache->getItem('ez-content-type-group-' . $groupId);
70
        if ($cacheItem->isHit()) {
71
            return $cacheItem->get();
72
        }
73
74
        $this->logger->logCall(__METHOD__, array('group' => $groupId));
75
        $group = $this->persistenceHandler->contentTypeHandler()->loadGroup($groupId);
76
77
        $cacheItem->set($group);
78
        $cacheItem->tag('type-group-' . $group->id);
79
        $this->cache->save($cacheItem);
80
81
        return $group;
82
    }
83
84
    /**
85
     * {@inheritdoc}
@@ 187-202 (lines=16) @@
184
    /**
185
     * {@inheritdoc}
186
     */
187
    public function loadByIdentifier($identifier)
188
    {
189
        $cacheItem = $this->cache->getItem('ez-content-type-' . $identifier . '-by-identifier');
190
        if ($cacheItem->isHit()) {
191
            return $cacheItem->get();
192
        }
193
194
        $this->logger->logCall(__METHOD__, array('type' => $identifier));
195
        $type = $this->persistenceHandler->contentTypeHandler()->loadByIdentifier($identifier);
196
197
        $cacheItem->set($type);
198
        $cacheItem->tag(['type-' . $type->id]);
199
        $this->cache->save($cacheItem);
200
201
        return $type;
202
    }
203
204
    /**
205
     * {@inheritdoc}
@@ 207-222 (lines=16) @@
204
    /**
205
     * {@inheritdoc}
206
     */
207
    public function loadByRemoteId($remoteId)
208
    {
209
        $cacheItem = $this->cache->getItem('ez-content-type-' . $remoteId . '-by-remote');
210
        if ($cacheItem->isHit()) {
211
            return $cacheItem->get();
212
        }
213
214
        $this->logger->logCall(__METHOD__, array('type' => $remoteId));
215
        $type = $this->persistenceHandler->contentTypeHandler()->loadByRemoteId($remoteId);
216
217
        $cacheItem->set($type);
218
        $cacheItem->tag(['type-' . $type->id]);
219
        $this->cache->save($cacheItem);
220
221
        return $type;
222
    }
223
224
    /**
225
     * {@inheritdoc}

eZ/Publish/Core/Persistence/Cache/NotificationHandler.php 3 locations

@@ 79-99 (lines=21) @@
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function countPendingNotifications(int $ownerId): int
80
    {
81
        $cacheItem = $this->cache->getItem('ez-notification-pending-count-' . $ownerId);
82
83
        $count = $cacheItem->get();
84
        if ($cacheItem->isHit()) {
85
            return $count;
86
        }
87
88
        $this->logger->logCall(__METHOD__, [
89
            'ownerId' => $ownerId,
90
        ]);
91
92
        $count = $this->persistenceHandler->notificationHandler()->countPendingNotifications($ownerId);
93
94
        $cacheItem->set($count);
95
        $cacheItem->tag(['notification-pending-count-' . $ownerId]);
96
        $this->cache->save($cacheItem);
97
98
        return $count;
99
    }
100
101
    /**
102
     * {@inheritdoc}
@@ 104-124 (lines=21) @@
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function countNotifications(int $ownerId): int
105
    {
106
        $cacheItem = $this->cache->getItem('ez-notification-count-' . $ownerId);
107
108
        $count = $cacheItem->get();
109
        if ($cacheItem->isHit()) {
110
            return $count;
111
        }
112
113
        $this->logger->logCall(__METHOD__, [
114
            'ownerId' => $ownerId,
115
        ]);
116
117
        $count = $this->persistenceHandler->notificationHandler()->countNotifications($ownerId);
118
119
        $cacheItem->set($count);
120
        $cacheItem->tag(['notification-count-' . $ownerId]);
121
        $this->cache->save($cacheItem);
122
123
        return $count;
124
    }
125
126
    /**
127
     * {@inheritdoc}
@@ 129-149 (lines=21) @@
126
    /**
127
     * {@inheritdoc}
128
     */
129
    public function getNotificationById(int $notificationId): Notification
130
    {
131
        $cacheItem = $this->cache->getItem('ez-notification-' . $notificationId);
132
133
        $notification = $cacheItem->get();
134
        if ($cacheItem->isHit()) {
135
            return $notification;
136
        }
137
138
        $this->logger->logCall(__METHOD__, [
139
            'notificationId' => $notificationId,
140
        ]);
141
142
        $notification = $this->persistenceHandler->notificationHandler()->getNotificationById($notificationId);
143
144
        $cacheItem->set($notification);
145
        $cacheItem->tag(['notification-' . $notificationId]);
146
        $this->cache->save($cacheItem);
147
148
        return $notification;
149
    }
150
151
    /**
152
     * {@inheritdoc}

eZ/Publish/Core/Persistence/Cache/ObjectStateHandler.php 2 locations

@@ 35-50 (lines=16) @@
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function loadGroup($groupId)
36
    {
37
        $cacheItem = $this->cache->getItem('ez-state-group-' . $groupId);
38
        if ($cacheItem->isHit()) {
39
            return $cacheItem->get();
40
        }
41
42
        $this->logger->logCall(__METHOD__, array('groupId' => $groupId));
43
        $group = $this->persistenceHandler->objectStateHandler()->loadGroup($groupId);
44
45
        $cacheItem->set($group);
46
        $cacheItem->tag(['state-group-' . $group->id]);
47
        $this->cache->save($cacheItem);
48
49
        return $group;
50
    }
51
52
    /**
53
     * {@inheritdoc}
@@ 55-70 (lines=16) @@
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function loadGroupByIdentifier($identifier)
56
    {
57
        $cacheItem = $this->cache->getItem('ez-state-group-' . $identifier . '-by-identifier');
58
        if ($cacheItem->isHit()) {
59
            return $cacheItem->get();
60
        }
61
62
        $this->logger->logCall(__METHOD__, array('groupId' => $identifier));
63
        $group = $this->persistenceHandler->objectStateHandler()->loadGroupByIdentifier($identifier);
64
65
        $cacheItem->set($group);
66
        $cacheItem->tag(['state-group-' . $group->id]);
67
        $this->cache->save($cacheItem);
68
69
        return $group;
70
    }
71
72
    /**
73
     * {@inheritdoc}

eZ/Publish/Core/Persistence/Cache/SectionHandler.php 2 locations

@@ 44-59 (lines=16) @@
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function load($id)
45
    {
46
        $cacheItem = $this->cache->getItem('ez-section-' . $id);
47
        if ($cacheItem->isHit()) {
48
            return $cacheItem->get();
49
        }
50
51
        $this->logger->logCall(__METHOD__, array('section' => $id));
52
        $section = $this->persistenceHandler->sectionHandler()->load($id);
53
54
        $cacheItem->set($section);
55
        $cacheItem->tag(['section-' . $section->id]);
56
        $this->cache->save($cacheItem);
57
58
        return $section;
59
    }
60
61
    /**
62
     * {@inheritdoc}
@@ 74-89 (lines=16) @@
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function loadByIdentifier($identifier)
75
    {
76
        $cacheItem = $this->cache->getItem('ez-section-' . $identifier . '-by-identifier');
77
        if ($cacheItem->isHit()) {
78
            return $cacheItem->get();
79
        }
80
81
        $this->logger->logCall(__METHOD__, array('section' => $identifier));
82
        $section = $this->persistenceHandler->sectionHandler()->loadByIdentifier($identifier);
83
84
        $cacheItem->set($section);
85
        $cacheItem->tag(['section-' . $section->id]);
86
        $this->cache->save($cacheItem);
87
88
        return $section;
89
    }
90
91
    /**
92
     * {@inheritdoc}

eZ/Publish/Core/Persistence/Cache/URLHandler.php 1 location

@@ 58-75 (lines=18) @@
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function loadById($id)
59
    {
60
        $cacheItem = $this->cache->getItem('ez-url-' . $id);
61
62
        $url = $cacheItem->get();
63
        if ($cacheItem->isHit()) {
64
            return $url;
65
        }
66
67
        $this->logger->logCall(__METHOD__, ['url' => $id]);
68
        $url = $this->persistenceHandler->urlHandler()->loadById($id);
69
70
        $cacheItem->set($url);
71
        $cacheItem->tag(['url-' . $id]);
72
        $this->cache->save($cacheItem);
73
74
        return $url;
75
    }
76
77
    /**
78
     * {@inheritdoc}

eZ/Publish/Core/Persistence/Cache/UserHandler.php 1 location

@@ 46-61 (lines=16) @@
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function load($userId)
47
    {
48
        $cacheItem = $this->cache->getItem("ez-user-${userId}");
49
        if ($cacheItem->isHit()) {
50
            return $cacheItem->get();
51
        }
52
53
        $this->logger->logCall(__METHOD__, array('user' => $userId));
54
        $user = $this->persistenceHandler->userHandler()->load($userId);
55
56
        $cacheItem->set($user);
57
        $cacheItem->tag(['content-' . $user->id, 'user-' . $user->id]);
58
        $this->cache->save($cacheItem);
59
60
        return $user;
61
    }
62
63
    /**
64
     * {@inheritdoc}

eZ/Publish/Core/Persistence/Cache/UserPreferenceHandler.php 1 location

@@ 42-61 (lines=20) @@
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function countUserPreferences(int $userId): int
43
    {
44
        $cacheItem = $this->cache->getItem('ez-user-preference-count-' . $userId);
45
46
        $count = $cacheItem->get();
47
        if ($cacheItem->isHit()) {
48
            return $count;
49
        }
50
51
        $this->logger->logCall(__METHOD__, [
52
            'userId' => $userId,
53
        ]);
54
55
        $count = $this->persistenceHandler->userPreferenceHandler()->countUserPreferences($userId);
56
        $cacheItem->set($count);
57
        $cacheItem->tag(['user-preference-count-' . $userId]);
58
        $this->cache->save($cacheItem);
59
60
        return $count;
61
    }
62
63
    /**
64
     * {@inheritdoc}