Support arbitrary number of db queries per model

Uptill now, all queries associated with the model were stored in one
cache entry (1MB limit) which limited the number of queries that
could be cached. Now the queries are stored in multiple cache entries
depending on the number of cached queries