[dancer-users] Plugin globals, and sharing database connections between plugins

Naveed Massjouni naveedm9 at gmail.com
Wed Feb 18 09:21:55 GMT 2015

On Wed, Feb 18, 2015 at 4:09 AM, Andrew Beverley <andy at andybev.com> wrote:
> On Wed, 2015-02-18 at 03:18 -0500, Naveed Massjouni wrote:
>> > The advantage of this is that you can reuse the same database connection
>> > handle. From what I can tell, reusing one plugin inside another would
>> > still open another database connection. Not a major issue, but it seems
>> > cleaner to use an existing one.
>> In the case of the DBIC plugin, its schema keyword is essentially
>> memoized (schema objects are cached in memory), so it would not open
>> another database connection. Unless of course if schema() was called
>> with a different argument.
> It's only memoized within each instantiation of the object. So if you
> "use Dancer2::Plugin::DBIC" within another plugin, you get a second
> connection. Correct?
> Andy

I don't think that is correct. The schema objects are cached in a
$schemas hashref that is lexically scoped to the Dancer2::Plugin::DBIC
There can only be one instance of this "cache" (the $schemas hashref)
per process.

> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users

More information about the dancer-users mailing list