Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cachability of g11n catalog pages. #1054

Open
mariuswilms opened this issue Jan 13, 2014 · 0 comments
Open

Improve cachability of g11n catalog pages. #1054

mariuswilms opened this issue Jan 13, 2014 · 0 comments

Comments

@mariuswilms
Copy link
Member

Originally reported by greut on dev.lithify.me:

What happened:

I wanted to cache Message just like Library (which is cached by default).
it turned out to be difficult because the pluralForm keys are not serializable (see the > workaround below)
What was expected:

to have a nice example of cached g11n by default into the app.
If this one works, it's not very nice…

<?php
// app/config/bootstrap/cache.php
use lithium\g11n\Message;
use lithium\g11n\Catalog;

Dispatcher::applyFilter('run', function($self, $params, $chain) {
    if ($cache = Cache::read('default', 'app.messages')) {
        $cache = (array) $cache + Message::cache();
        $file = Catalog::adapter('lithium');
        foreach ($cache as $scope => &$locales) {
            foreach ($locales as $locale => &$messages) {
                $default = $file->read('message', $locale, $scope);
                $messages['pluralRule'] = $default['pluralRule']['translated'];
            }
        }
        Message::cache($cache);
    }

    $result = $chain->next($self, $params, $chain);

    if ($cache != Message::cache()) {
        $cache = Message::cache();
        foreach ($cache as &$scope) {
            foreach ($scope as &$messages) {
                unset($messages['pluralRule']);
            }
        }
        Cache::write('default', 'app.messages', $cache, '+1 hour');
    }
    return $result;
});
@mariuswilms mariuswilms modified the milestone: future Sep 30, 2014
@mariuswilms mariuswilms added this to the 1.1 milestone Mar 17, 2015
@mariuswilms mariuswilms modified the milestones: 1.2, 1.1 May 24, 2016
@mariuswilms mariuswilms removed this from the 1.2 milestone Feb 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant