title: Caching MySQL results with Memcache and sorting/filtering cached results
body: <p>To help everyone understand what I'm asking I put forward a scenario:</p>
  
  <p>I have user A on my web app.</p>
  
  <p>There is a particular page which has a table that contains information that is unique to that user. Let's say it is a list of customers that only show for user A because user A and these customers are in region 5.</p>
  
  <p>Other users are assigned to different regions and see different lists of customers.</p>
  
  <p>What I would like to do is cache all of the results for each users list. This isn't a problem as I can use:</p>
  
  <pre><code>    $MC = new Memcache;
  
      $MC-&gt;addserver('localhost');
      $data = $MC-&gt;get('customers');
      if($data)
      {
  
      } else {
          $data = $this-&gt;model-&gt;customersGrid($take, $skip, $page, $pageSize, $sortColumn, $sortDirection, $filterSQL, $PDOFilterParams);
          $MC-&gt;set('customers', $data);
      }
      header('Content-Type: application/json');
      return $data;
  </code></pre>
  
  <p>The challenge now is to somehow convert the SQL filter syntax that comes from my users table into a function that can filter and sort an array ($data is a JSON string that I would turn into an array if that's the right way to go).</p>
  
  <p>Just for reference, here is the array of aliases I use for building the WHERE clause in my statements:</p>
  
  <pre><code>    $KF = new KendoFilter;
      $KF-&gt;columnAliases = array(
          'theName' =&gt; 'name',
          'dimensions' =&gt; 'COALESCE((SELECT CONCAT_WS(" x ", height, width, CONCAT(length, unit)) FROM products_dimensions,
           system_prefs, units_measurement
           WHERE products_dimensions.productId = product.id
           AND units_measurement.id = system_prefs.defaultMeasurementId), "-")',
          'gridSearch' =&gt; array('theName', 'basePrice')
      );
      $filterSQL = $KF-&gt;buildFilter();
  </code></pre>
  
  <p>My question is what is a good way to filter and sort memcache data as if it was an SQL query? Or does memcache have something already built in?</p>