improving social cache retrieval sql