schotime/NPoco — pull request #134 by Shandem (2014-09-25 08:07:34+00:00)
Title: Non parameterized queries can cause high memory usage

This PR is based off of the information in this blog post:

http://shazwazza.com/post/petapoco-can-cause-high-memory-usage-with-certain-queries/

I've created the PR for NPoco because it actually seems like it's active. I'll log a bug on PetaPoco too with a reference to this PR just for completeness.

This issue probably doesn't affect a majority of people but if developers don't know about this, memory usage can grow quite large. One of my projects used a Linq based approach to generating queries which didn't use parameters and just implemented them in strings... in a couple of days the memory usage for m_PocosData grew to over 150 mb.

I found all of this out because the site was using far more memory than needed and it was clearly slowly growing. So i created a memory dump and had a look and all the extra mem was in m_PocosData.

This PR fixes a couple of the points in that blog post:

* Small hashed keys instead of giant strings
* Sliding expiration for the cached delegates

I've put a TODO in the code to remove the irrelevant parts of the query that is used to cache (as noted in the blog post).