19declare(strict_types=1);
44 $settings = new \ilSetting(
'news');
46 $this->cache_ttl = (
int) $settings->get(
'acc_cache_mins');
47 $this->enabled = $this->cache_ttl !== 0;
49 $this->il_cache = new \ilCache(
'ServicesNews',
'NewsMultiLevel',
true);
50 $this->il_cache->setExpiresAfter($this->cache_ttl * 60);
63 if (!$this->enabled || empty($contexts)) {
64 return [
'hit' => [],
'missing' => $contexts];
68 sort($context_ids, SORT_NUMERIC);
70 if ($entry = $this->il_cache->getEntry($this->generateL1Key($context_ids))) {
72 return [
'hit' => $contexts,
'missing' => []];
75 return [
'hit' => [],
'missing' => $contexts];
80 return 'agg:' . md5(is_array($contexts) ? implode(
',', $contexts) : $contexts);
89 if (!$this->enabled || empty($contexts)) {
94 sort($context_ids, SORT_NUMERIC);
95 $key = implode(
',', $context_ids);
106 if (!$this->enabled || empty($contexts)) {
111 sort($context_ids, SORT_NUMERIC);
112 $key = implode(
',', $context_ids);
127 if (!$this->enabled) {
131 $entry = $this->il_cache->getEntry(
"access:{$user_id}");
151 if (!$this->enabled) {
157 $this->il_cache->storeEntry(
"access:{$user_id}", serialize(
$payload));
162 if ($this->enabled) {
163 $this->il_cache->deleteEntry(
"access:{$user_id}");
174 if (!$this->enabled) {
178 $entry = $this->il_cache->getEntry($this->
generateL3Key($user_id, $criteria));
190 if (!$this->enabled) {
194 $this->il_cache->storeEntry(
202 $this->il_cache->deleteEntry($this->
generateL3Key($user_id, $criteria));
215 $period_minutes = ($criteria->
getPeriod() ?? 0) * 1440;
216 if ($period_minutes <= $this->cache_ttl) {
220 return "user:{$user_id}:" . md5(serialize(
$payload));
226 $this->il_cache->deleteAllEntries();
This class is a special implementation of a NewsCollection that is designed to load the complete News...
Optimized News Collection with memory-efficient data structures to support large news feeds.
getUserReadStatus(int $user_id)
News Context DTO represents a context where news items can be associated with.
static denormalize(array $raw)
Create new object from reduced array representation.
News Criteria DTO for querying news items supports caching, JSON serialization, and validation.
Multi-Level News Cache Implementation:
invalidateNewsForUser(int $user_id, NewsCriteria $criteria)
storeUserContextAccess(int $user_id, NewsCriteria $criteria, array $contexts)
storeNewsForUser(int $user_id, NewsCriteria $criteria, NewsCollection $news)
getUserContextAccess(int $user_id, NewsCriteria $criteria)
Level-2 Cache stores a collection of the base news contexts for a specific user.
generateL1Key(string|array $contexts)
invalidateUserContextAccess(int $user_id)
storeAggregatedContexts(array $contexts, array $aggregated)
readonly ilCache $il_cache
getNewsForUser(int $user_id, NewsCriteria $criteria)
Level-3 Cache stores a collection of the news items for a specific user.
getAggregatedContexts(array $contexts)
Level-1 Cache stores a collection of the aggregated contexts for the provided base context.
generateL3Key(int $user_id, NewsCriteria $criteria)
invalidateAggregatedContexts(array $contexts)
if(count($parts) !=3) $payload