ORM关系缓存 [英] ORM Relation Caching

查看:159
本文介绍了ORM关系缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有未使用的单词,我需要一些建议。



我正在建立另一个基于KohanaPHP 3.0.9框架的应用程序,感觉爱上ORM 。)。



我有Model_User模型:

  class Model_User extends ORM 
{
protected $ _table_name ='users';
protected $ _primary_key ='id';

protected $ _has_many = array(
'articles'=> array(
'through'=>'users_articles',
),
);

protected $ _ignored_columns = array('articles');
}



我已经使用了瘦控制器/脂肪模型哲学,所以正确的数据位置



$ _ ignored_columns 是什么?在少数地方,我需要返回 $ user 对象,所以我返回它与文章(如果需要)作为$用户方法: $ user-> ; articles-> find_all();



到目前为止很好,一切都很好。我不太确定如果我的方法与 $ _ ignored_columns 是正确的,如果没有,请让我知道如何解决它的建议。



但是,我面临着缓存的问题。一般来说,一切都正常工作期望文章。它只是被缓存忽略(不保存在缓存文件中)。

解决方案

任何建议? div>

忽略的列只是模型中的一些假想字段,ORM不会尝试保存save()(如Model_Auth_User中的password_confirm字段)



我真的不明白为什么你会缓存文章,因为它没有真正有意义,虽然你必须手动进行(如添加额外的get_articles()方法,将检查是否有缓存当前加载文章并返回它),但你会只是让自己头痛没有特别的原因(查询真的是多慢,它是通过主键通过数据透视表选择)。



默认情况下,ORM不支持任何缓存(表列除外)。


Without unused words, I need some advice.

I'm building another app basing on KohanaPHP 3.0.9 framework, felt in love with ORM (Real productivity booster!).

I got Model_User model:

class Model_User extends ORM
{
    protected $_table_name = 'users';
    protected $_primary_key = 'id';

    protected $_has_many = array(
        'articles' => array(
            'through' => 'users_articles',
        ),
    );

    protected $_ignored_columns = array('articles');
}

I have gone with thin controller/fat model philosophy so the correct place for data is model in my development.

What is $_ignored_columns? In few places I need to return $user object so I'm returning it with articles (when needed) as $user method: $user->articles->find_all();

So far so good, everything is working really perfectly. I'm not quite sure if my approach with $_ignored_columns is correct, if not, please let me know with advice how to solve it.

However, I'm facing an issue with caching. Generally, everything is working correctly expect articles. It just gets ignored by cache (not saved in cache file). I also tried to cache it separately - still without luck.

Any suggestions?

解决方案

Ignored columns are just some "imaginary" fields you can have in a model, which ORM will not try to save on save() (like password_confirm field in Model_Auth_User)

I don't really see why you would cache articles as it doesn't really make much sense, though you'll have to do it manually (like adding additional get_articles() method which will check if there's cache for currently loaded article and return it), but you'll be just getting yourself a headache for no particular reason (how slow the query really is, it's a select by primary key through a pivot table?).

ORM doesn't support any caching by default (except for table columns).

这篇关于ORM关系缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆