BeanFactory is a great way to load and query for beans without
For example we can load an Account with a known id:
$bean = BeanFactory::getBean('Accounts', '1234');
However this method can cause some unexpected behaviour. Let’s look at the following example: wzxhzdk:1
This produces the following output:
Acc1 Name: Bar Acc2 Name: Bar Acc1 Name: Bar Acc2 Name: Bar Acc3 Name: Foo
Enter the cache
So what is going on here?
getBean method is cached.
getBean will cache at most
10 beans and drop some of the older entries based on usage.
pulled from the cache and is therefore the same instance as
changes in one will be reflected in the other.
However when we load a bunch of beans our cached account drops out the
BeanFactory Cache and when we fetch the bean into
$acc3 we get a fresh
instance from the database.