protected function i18n_string_textgroup_cached::multiple_cache_get in Internationalization 7
Get strings from multiple cache.
Parameters
$context array: String context as array with language property at the end.
Return value
mixed Array of strings (may be empty) if we've got a cache hit. Null otherwise.
Overrides i18n_string_textgroup_default::multiple_cache_get
File
- i18n_string/
i18n_string.inc, line 1483 - API for internationalization strings
Class
- i18n_string_textgroup_cached
- Textgroup handler for i18n_string API which integrated persistent caching.
Code
protected function multiple_cache_get($context) {
// Ensure the values from the persistent cache are properly re-build.
$cache_key = implode(':', $context);
if (isset($this->cache_multiple[$cache_key])) {
foreach ($this->cache_multiple[$cache_key] as $cached_context) {
if (is_string($cached_context)) {
$i8n_string_object = new i18n_string_object(array(
'textgroup' => $this->textgroup,
));
$i8n_string_object
->set_context($cached_context);
$this->cache_multiple[$cache_key][$cached_context] = $i8n_string_object;
}
}
}
else {
// Now we try more generic keys. For instance, if we are searching 'term:1:*'
// we may try too 'term:*:*' and filter out the results.
foreach ($context as $key => $value) {
if ($value != '*') {
$try = array_merge($context, array(
$key => '*',
));
$cached_results = $this
->multiple_cache_get($try);
// Now filter the ones that actually match.
if (!empty($cached_results)) {
$cached_results = $this
->string_filter($cached_results, $context);
}
return $cached_results;
}
}
}
return parent::multiple_cache_get($context);
}