I found this question How to cache data in a MVC application and I'm wondering about being able to use this method with IQueryable data.
Public Function GetUsers() As IQueryable(Of User) Implements IUserRepository.GetUsers
Dim users = (From u In dc.Users
Select u)
Return users.AsQueryable
End Function
Can I change this to
Public Function GetUsers() As IQueryable(Of User) Implements IUserRepository.GetUsers
Dim users = Cache("users")
If users Is Nothing Then
users = (From u In dc.Users
Select u)
Cache("users") = users
End If
Return users.AsQueryable
End Function
You can do it yes, but it won't have the desired effect since (assuming dc is a linq to sql data context) an IQueryable is not a collection of data, it is a stored query which will execute later, you will need to store an IList or similar, you could still return it as an IQueryable if desired, though that could be confusing to others.
Use ToList() before caching it.