> Singleton only if you have base model class, and/or only for
> default cache (BaseModel::setDefaultCache(),
> BaseModel::getDefaultCache()).
This implies that you have multiple cache instances.
If you don't, singleton is the best approach.
If you do, your cache instances will vary in their options
(e.g., type of backend, lifetime). If so, you'd at best
still have a method that returns you the instance for the
specified options, and internally, the method might check
whether an instance with this gestalt has already been
created, otherwise create it.
This would be some sort of multiton pattern, wouldn't it?
> Otherwise singleton is wrong approach.
And yes, this would even make sense if you didn't have a
base model class.
Best regards,
Andreas
没有评论:
发表评论