title: ASP.NET MVC - Caching IQueryable Data
body: <p>I found this question <a href="https://stackoverflow.com/questions/343899/how-to-cache-data-in-a-mvc-application">How to cache data in a MVC application</a> and I'm wondering about being able to use this method with IQueryable data.</p>
  
  <pre><code>    Public Function GetUsers() As IQueryable(Of User) Implements IUserRepository.GetUsers 
          Dim users = (From u In dc.Users 
                      Select u) 
          Return users.AsQueryable 
      End Function 
  </code></pre>
  
  <p>Can I change this to </p>
  
  <pre><code>    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
  </code></pre>