On Wed, 2015-02-18 at 04:21 -0500, Naveed Massjouni wrote:
On Wed, Feb 18, 2015 at 4:09 AM, Andrew Beverley <andy@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 package. https://github.com/ironcamel/Dancer2-Plugin-DBIC/blob/master/lib/Dancer2/Plu... There can only be one instance of this "cache" (the $schemas hashref) per process.
Okay, I'll need to look at it a bit more closely then. When I did some initial testing with reusing the DBIC plugin within DPAE, the $schemas hashref was undefined when called from DPAE, despite having being defined in the main Dancer App. But I could have been doing something wrong. Thanks, Andy