I'd appreciate some feedback on my logic to optimise my cache (under mod_perl 1)

I'm building a site which will have a large number of fairly complicated objects (each of which would require 5-20 queries to build from scratch) which are read frequently and updated relatively seldom.

I'm planning a two level cache :
    1) Live objects in each mod_perl process
    2) Serialised objects in a database

The logic goes as follows :
NORMAL READ-ONLY REQUEST
1) REQUEST FROM BROWSER
     * Request comes from browser to view for object 12345
       (responding to this request may involve accessing 10 other objects)
2) PURGE OUTDATED LIVE OBJECTS
    * mod_perl process runs a query to look for the ID's of any objects
      that have been updated since the last time this
      query was run (last_modified_time).
    * Any object IDs returned by this request have their objects removed
      from the in-memory mod_perl process specific cache
3) REQUEST IS PROCESSED
    * Any objects required by this request are retrieved first from
      the in-memory cache.
    * If they are not present,
          * the process looks in the serialised object cache in the database.
          * If not present there either,
                * the object is constructed from scratch the relational DB.
                  and stored in the serialised object cache
          * retrieved object is store in the in-memory live object cache 
4) TRIM LIVE OBJECT CACHE
    * Any live objects that are not in the 1000 most recently accessed
      objects are deleted from the in-memory cache


UPDATE REQUEST
Steps as above except :
3a) UPDATING OBJECT
     * Any objects that are modified
         * are deleted from the serialised object cache in the DB
         * and are deleted from the in-memory cache for this mod_perl
            process only


This means that at the start of every request, each process has access to the most up to date versions of each object with a small (hopefully) penalty to pay in the form of the query checking for last_modified_time.

Does this sound reasonable or is overkill

many thanks

Clinton Gormley

Reply via email to