Elgg  Version 3.0
PrivateSettingsCache.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Cache;
3 
4 use Elgg\Values;
5 use ElggCache;
6 
13 
17  protected $cache;
18 
24  public function __construct(ElggCache $cache) {
25  $this->cache = $cache;
26  }
27 
35  public function load($key) {
36  return $this->cache->load($key);
37  }
38 
48  public function save($key, $data, $expire_after = null) {
49  return $this->cache->save($key, $data, $expire_after);
50  }
51 
58  public function populateFromEntities(...$guids) {
59  try {
61  } catch (\DataFormatException $e) {
62  return null;
63  }
64 
65  if (empty($guids)) {
66  return null;
67  }
68 
69  $cached_values = [];
70 
71  foreach ($guids as $i => $guid) {
72  $value = $this->load($guid);
73  if ($value !== null) {
74  $cached_values[$guid] = $value;
75  unset($guids[$i]);
76  }
77  }
78 
79  if (empty($guids)) {
80  return $cached_values;
81  }
82 
83  $data = _elgg_services()->privateSettings->getAllForGUIDs($guids);
84 
85  // store always for every guid, even if there is no settings
86  foreach ($guids as $guid) {
87  $settings = elgg_extract($guid, $data, []);
88 
89  $this->save($guid, $settings);
90  $cached_values[$guid] = $settings;
91  }
92 
93  return $cached_values;
94  }
95 }
static normalizeGuids(...$args)
Flatten an array of data into an array of GUIDs.
Definition: Values.php:139
save($key, $data, $expire_after=null)
Save data in a cache.
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:57
$guid
Removes an admin notice.
__construct(ElggCache $cache)
Constructor.
load($key)
Load data from the cache using a given key.
In memory cache of known private settings values stored by entity.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1131
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
$guids
Activates all specified installed and inactive plugins.
Definition: activate_all.php:9
$value
Definition: debugging.php:7
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
$settings
Definition: settings.php:3
populateFromEntities(...$guids)
Populate the cache from a set of entities.