fixes PowerDNS/pdns#693

removes number of static variables and makes them class, also optimizes if query cache is disabled.
Merge pull request #1136 from mzealey/backend-cache-optimization

fixes PowerDNS/pdns#693