I need to fetch and show data on a webpage whose number of records may vary based on filters from around 500 records to 1 million records.
Will caching be of any use her
If your server can't cache 1 million records how do you think your user's web browser is going to handle 1 million records worth of HTML coming at it?
Consider paging (here is an example with 1 million records)
Also consider that the user never wants more than about 30 to 50 records. You are either showing them too low level of detail, or you need more filtering.