|<B>apache_has_started [BOOL]B>||Get or set a boolean value indicating whether or not apache has completed its startup process. If this value is not set explicitly, a best guess as to the answer will be returned.|
|<B>build_cache_key PARAMSB>||Given the name/value pairs PARAMS, return a string representing the corresponding cache key. Calls to this method from within Rose::DB::Cache will include at least type and domain parameters, but you may pass any parameters if you override all methods that call this method in your subclass.|
|<B>default_use_cache_during_apache_startup [BOOL]B>||Get or set a boolean value that determines the default value of the use_cache_during_apache_startup object attribute. The default value is false. See the use_cache_during_apache_startup documentation for more information.|
|<B>entry_class [CLASS]B>||Get or set the name of the Rose::DB::Cache::Entry-derived class used to store cached Rose::DB objects on behalf of this class. The default value is Rose::DB::Cache::Entry.|
<B>new PARAMSB> Constructs a new Rose::DB::Cache object based on PARAMS, where PARAMS are name/value pairs. Any object method is a valid parameter name.
<B>clearB> Clear the cache entirely. <B>db_cache_entriesB> Returns a list (in list context) or reference to an array (in scalar context) of cache entries for each cached db object. <B>db_cache_keysB> Returns a list (in list context) or reference to an array (in scalar context) of keys for each L <cache entries|Rose::DB::Cache::Entry>. <B>get_db [PARAMS]B> Return the cached Rose::DB-derived object corresponding to the name/value pairs passed in PARAMS. PARAMS are passed to the build_cache_key method, and the key returned is used to look up the cached object.
If no such object exists in the cache, undef is returned.
<B>prepare_for_apache_forkB> Prepares the cache for the initial fork of the apache parent process by disconnect()ing all database handles and deleting all cache entries that were created during apache startup. This call is only necessary if running under mod_perl and use_cache_during_apache_startup set set to true. See the use_cache_during_apache_startup documentation for more information. <B>prepare_db [DB, ENTRY]B> Prepare the cached Rose::DB-derived object DB for usage. The cacheds db objects Rose::DB::Cache::Entry object, ENTRY, is also passed.
When NOT running under mod_perl, this method does nothing.
When running under mod_perl (version 1.x or 2.x), this method will do the following:
o Any DBI database handle created inside a Rose::DB object during apache server startup will be marked as such. Any attempt to use such an object after the apache startup process has completed (i.e., in a child apache process) will cause it to be discarded and replaced. Note that you usually dont want it to come to this. Its better to cleanly disconnect all such database handles before the first apache child forks off. See the documentation for the use_cache_during_apache_startup and prepare_for_apache_fork methods for more information. o All DBI database handles contained in cached Rose::DB objects will be cleared at the end of each request using a PerlCleanupHandler. This will cause DBI->connect to be called the next time a dbh is requested from a cached Rose::DB object, which in turn will trigger Apache::DBIs ping mechanism to ensure that the database handle is fresh.
Putting all the pieces together, the following implementation of the init_db method in your Rose::DB::Object-derived common base class will ensure that database connections are shared and fresh under mod_perl and (optionally) Apache::DBI, but unshared elsewhere:
<B>set_db DBB> Add the Rose::DB-derived object DB to the cache. The DBs domain, type, and the db object itself (under the parameter name db) are all are passed to the build_cache_key method and the DB object is stored under the key returned. <B>use_cache_during_apache_startup [BOOL]B> Get or set a boolean value that determines whether or not to cache database objects during the apache server startup process. The default value is determined by the default_use_cache_during_apache_startup class method.
DBI database handles created in the parent apache process cannot be used in child apache processes. Furthermore, in the case of at least one one DBI driver class, you must also ensure that any database handles created in the apache parent process during server startup are properly disconnect()ed before you fork off the first apache child. Failure to do so may cause segmentation faults(!) in child apache processes.
The upshot is that if use_cache_during_apache_startup is set to true, you should call prepare_for_apache_fork at the very end of the apache startup process (i.e., once all other Perl modules have been loaded and all other Perl code has run). This is usually done by placing a call at the bottom of the traditional startup.pl file. Assuming My::DB is your Rose::DB-derived class:
A convenience method exists in Rose::DB as well, which simply translates into call shown above:
John C. Siracusa (firstname.lastname@example.org)
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|perl v5.20.3||ROSE::DB::CACHE (3)||2015-03-17|