title: How to cache a cursor object?
body: <p>I have a huge database (SQLite Engine) in my application, I need to run a query once a week and cache the cursor of that query to re-use it later, So I wrote the following function to save my cursor through <code>ObjectStream</code> but I'm not able to load it via <code>ObjectInputStream</code> because it's not serializable!!!</p>
  
  <p>Any ideas on how to accomplish this functionality?</p>
  
  <pre><code>public Cursor getCachedCursor(ReaderState state, String[] allowedColumns
          , String sortType, int limit) throws IOException, ClassNotFoundException
  {
      File cacheFilePath = CacheManager.getCachePath(state.toString() + ".cached");
      Cursor mCursor = null;
  
      try
      {
          if (cacheFilePath == null)
          { 
               FileOutputStream mFileOutputStream = new FileOutputStream(cacheFilePath);
               ObjectOutputStream mObjectOutputStream = new ObjectOutputStream(mFileOutputStream);
  
               mObjectOutputStream.writeObject(mDatabase.query(TABLE_NAME, allowedColumns, null, null
                       , null, null, sortType, String.valueOf(limit)));
  
               mObjectOutputStream.close();
          }
      }
      finally
      {
          FileInputStream mFileInputStream = new FileInputStream(cacheFilePath);
          ObjectInputStream mObjectInputStream = new ObjectInputStream(mFileInputStream);
  
          mCursor = (Cursor) mObjectInputStream.readObject();
  
          mObjectInputStream.close();
      }
  
      return mCursor;
  }
  </code></pre>