开发者

caching a large list in a cakephp model

I have a large array that I have implemented as a 'Vendor' file. I load the file in the controller using

App::import('Vendor', 'constants_helper');

This works well.

However, I need to use this array in another model. Within the model I have

App::import('Vendor', 'constants_helper');
class MyModel extends AppModel {


    function afterFind($results) {
        if (!isset($constantsHelper)) {
            $constantsHelper = new ConstantsHelper();
        }

        $constantsHelper = new ConstantsHelper();
        $list= $constantsHelper->mylist;
 }
}

This seems to load the list. However I have 2 questions

1. Is this the cakey (right) way to load the list ? 2. How can I cache this list , I dont want it reloaded for every model 开发者_运维百科 invocation.

Thanks


You shouldn't call it a helper, because in cake, a helper is a view extension. I don't know the structure of the file, but maybe you can import that into a table in the db; or just define an array in the model, depends on how you want to use it in your app (just in that afterFind method, or also somewhere else?). And how big is it exactly? a few MB?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜