I also wrapped my ORM many times, I hate talking! Caching / Storing is pretty simple if all of your selections happen through one api (or their subclasses).
For any selection based on a unique key, you can simply cache based on key concatenation. A naive approach could be:
my %_cache;
sub get_object_from_db {
my ($self, $table, %table_lookup_key) = @_;
my $cache_key = join('|', map { "$_|$table_lookup_key{$_}" }
sort keys %table_lookup_key
return $_cache{$cache_key}
if exists $_cache{$cache_key};
}
Instead of a hash, you can use the Cache :: suite of modules in CPAN to implement time and memory restrictions in your cache.
If you intend to cache for some time, you may need to think about the possibility of expiration of objects in the cache. If, for example, all of your updates also go through ORM, you can clear (or update) the cache entry in the update ORM () method.
, , - , . , , , db, , , . , - , , , . , , setter , . , .