[Dbix-class] Storing ResultSets in the schema
Ash Berlin
ash_cpan at firemirror.com
Mon Jul 7 10:13:05 BST 2008
On 7 Jul 2008, at 09:13, Tobias Kremer wrote:
> 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
Yes, that would create a memory leak due to circular reference. You
want Scalar::Util::weaken.
-ash
More information about the DBIx-Class
mailing list