implementing database cache