Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 408395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:41:17+00:00 2026-05-12T17:41:17+00:00

I have a set of rather complex ORM modules that inherit from Class::DBI .

  • 0

I have a set of rather complex ORM modules that inherit from Class::DBI. Since the data changes quite infrequently, I am considering using a Caching/Memoization layer on top of this to speed things up. I found a module: Class::DBI::Cacheable but no rating or any reviews on RT. I would appreciate hearing from people who have used this or any other Class::DBI caching scheme.

Thanks a ton.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:41:17+00:00Added an answer on May 12, 2026 at 5:41 pm

    I too have rolled my own ORM plenty of times I hate to say! Caching/Memoization is pretty easy if all your fetches happen through a single api (or subclasses thereof).

    For any fetch based on a unique key you can just cache based on a concatenation of the keys. A naive approach might be:

    my %_cache;
    
    sub get_object_from_db {
        my ($self, $table, %table_lookup_key) = @_;
    
        # concatenate a unique key for this object
        my $cache_key = join('|', map { "$_|$table_lookup_key{$_}" }
                           sort keys %table_lookup_key
    
        return $_cache{$cache_key}
            if exists $_cache{$cache_key};
    
        # otherwise get the object from the db and cache it in the hash
        # before returning
    }
    

    Instead of a hash, you can use the Cache:: suite of modules on CPAN to implement time and memory limits in your cache.

    If you’re going to cache for some time you might want to think about a way to expire objects in the cache. If for instance all your updates also go through the ORM you can clear (or update) the cache entry in your update() ORM method.

    A final point to think carefully about – you’re returning the same object each time which has implications. If, eg., one piece of code retrieves an object and updates a value but doesn’t commit that change to the db, all other code retrieving that object will see that change. This can be very useful if you’re stringing together a series of operations – they can all update the object and then you can commit it at the end – but it may not be what you intend. I usually set a flag on the object when it is fresh from the database and then in your setter method invalidate that flag if the object is updated – that way you can always check that flag if you really want a fresh object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of objects that I want to conform to an interface,
I have set up the Google Analytics in my FBML facebook application. It works
For my work I have to set up a project in Matlab, which is
Is there any way to tell if a cookie is set for .domain.com rather
I am struggling with an SQL time comparison on two fields that have been
I have a Silverlight 4 application and I cleverly name my apps by whatever
I have working C++ code using swig which creates a struct, passes it to
Background: I have a bird view's JavaScript game where the player controls a space
Hoping to get some clear advice on this one. I want to push updates
I've got a Windows 7 machine upon which I do both PHP/MySql Dev, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.