Rose::DB::Object::Cached is a subclass of Rose::DB::Object that is backed by a write-through memory cache. Whenever an object is loaded from or saved to the database, it is cached in memory. Any subsequent attempt to load an object of the same class with the same primary key or unique key value(s) will give you the cached object instead of loading from the database.

This means that modifications to an object will also modify all other objects in memory that have the same primary key. The synopsis above highlights this fact.

This class is most useful for encapsulating "read-only" rows, or other data that is updated very infrequently. In the Category example above, it would be inefficient to repeatedly load category information in a long-running process (such as a mod_perl Apache web server) if that information changes infrequently.

The memory cache can be cleared for an individual object or all objects of the same class. There is also support for simple time-based cache expiration. See the clear_object_cache and cached_objects_expire_in methods for more information.

Only the methods that are overridden or otherwise behaviorally modified are documented here. See the Rose::DB::Object documentation for the rest.

If called with no arguments, the cache expiration limit in seconds is returned. If passed a DURATION, the cache expiration is set. Valid formats for DURATION are in the form "NUMBER UNIT" where NUMBER is a positive number and UNIT is one of the following:

If set to a true value, then the data is always loaded from the database rather than from the memory cache. If the load succeeds, the object replaces whatever was in the cache. If it fails, the cache is not modified.

Returns true if the object was loaded successfully, false if the row could not be loaded or did not exist in the database. The true value returned on success will be the object itself. If the object overloads its boolean value such that it is not true, then a true value will be returned instead of the object itself.

This method does the same thing as the Rose::DB::Objectmethod of the same name, except that it also saves the object to the memory cache if the insert succeeds. If it fails, the memory cache is not modified.

Save the current object to the memory cache without saving it to the database as well. The object will be cached based on its primary key value only. This is unlike the remeber method which caches objects based on their primary key values and all their unique key values.

This method does the same thing as the Rose::DB::Objectmethod of the same name, except that it also saves the object to the memory cache if the save succeeds. If it fails, the memory cache is not modified.

This method does the same thing as the Rose::DB::Objectmethod of the same name, except that it also saves the object to the memory cache if the update succeeds. If it fails, the memory cache is not modified.