[Dbix-class] Storing ResultSets in the schema

Tobias Kremer list at funkreich.de
Mon Jul 7 09:13:08 BST 2008


On server startup I'd like to fetch the complete data of one table and store it
somewhere to allow faster retrieval of it later on. For this, I have added an
attribute to my DBIC schema class which is set during server startup with the
result of my ResultSet->search operation.

Basically the data stored in the schema is generated in a custom ResultSet class
with this:

  $data->{ $_->code } = $_ for $self->search->all;

The $data hashref is then stored in $schema during the start of MyApp with:

  $schema->foo_data( $data );  # foo_data being my custom attribute

Later on, I can access the data hashref with:

  $schema->get_foo_by_key( $key )

and get back the ResultSet preloaded during server start corresponding to $key.

Now, I'm wondering if storing complete ResultSets in the schema might be a bad
thing? I'm especially worried about creating memory leaks and/or circular
references.

Thanks!

--Tobias



More information about the DBIx-Class mailing list