diff --git a/CRM/Contact/Form/Task.php b/CRM/Contact/Form/Task.php
index 369d59451367..2c03f1e7233c 100644
--- a/CRM/Contact/Form/Task.php
+++ b/CRM/Contact/Form/Task.php
@@ -165,9 +165,6 @@ public static function preProcessCommon(&$form) {
     if ((CRM_Utils_Array::value('radio_ts', self::$_searchFormValues) == 'ts_all') ||
       ($form->_task == CRM_Contact_Task::SAVE_SEARCH)
     ) {
-      $sortByCharacter = $form->get('sortByCharacter');
-      $cacheKey = ($sortByCharacter && $sortByCharacter != 'all') ? "{$cacheKey}_alphabet" : $cacheKey;
-
       // since we don't store all contacts in prevnextcache, when user selects "all" use query to retrieve contacts
       // rather than prevnext cache table for most of the task actions except export where we rebuild query to fetch
       // final result set
diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php
index 066e4a4476fd..ad5bcdd0b07e 100644
--- a/CRM/Contact/Selector.php
+++ b/CRM/Contact/Selector.php
@@ -903,7 +903,6 @@ public function buildPrevNextCache($sort) {
     $countRow = Civi::service('prevnext')->getCount($cacheKey);
     // $sortByCharacter triggers a refresh in the prevNext cache
     if ($sortByCharacter && $sortByCharacter != 'all') {
-      $cacheKey .= "_alphabet";
       $this->fillupPrevNextCache($sort, $cacheKey, 0, max(self::CACHE_SIZE, $pageSize));
     }
     elseif (($firstRecord + $pageSize) >= $countRow) {
diff --git a/CRM/Core/PrevNextCache/Sql.php b/CRM/Core/PrevNextCache/Sql.php
index 2f20a63ba967..6483fda8acac 100644
--- a/CRM/Core/PrevNextCache/Sql.php
+++ b/CRM/Core/PrevNextCache/Sql.php
@@ -97,13 +97,13 @@ public function markSelection($cacheKey, $action, $cIds = NULL) {
       if (is_array($cIds)) {
         $cIdFilter = "(" . implode(',', $cIds) . ")";
         $whereClause = "
-WHERE cacheKey LIKE %1
+WHERE cacheKey = %1
 AND (entity_id1 IN {$cIdFilter} OR entity_id2 IN {$cIdFilter})
 ";
       }
       else {
         $whereClause = "
-WHERE cacheKey LIKE %1
+WHERE cacheKey = %1
 AND (entity_id1 = %2 OR entity_id2 = %2)
 ";
         $params[2] = array("{$cIds}", 'Integer');
@@ -111,12 +111,12 @@ public function markSelection($cacheKey, $action, $cIds = NULL) {
       if ($action == 'select') {
         $whereClause .= "AND is_selected = 0";
         $sql = "UPDATE civicrm_prevnext_cache SET is_selected = 1 {$whereClause} {$entity_whereClause}";
-        $params[1] = array("{$cacheKey}%", 'String');
+        $params[1] = array($cacheKey, 'String');
       }
       elseif ($action == 'unselect') {
         $whereClause .= "AND is_selected = 1";
         $sql = "UPDATE civicrm_prevnext_cache SET is_selected = 0 {$whereClause} {$entity_whereClause}";
-        $params[1] = array("%{$cacheKey}%", 'String');
+        $params[1] = array($cacheKey, 'String');
       }
       // default action is reseting
     }
@@ -124,10 +124,10 @@ public function markSelection($cacheKey, $action, $cIds = NULL) {
       $sql = "
 UPDATE civicrm_prevnext_cache
 SET    is_selected = 0
-WHERE  cacheKey LIKE %1 AND is_selected = 1
+WHERE  cacheKey = %1 AND is_selected = 1
        {$entity_whereClause}
 ";
-      $params[1] = array("{$cacheKey}%", 'String');
+      $params[1] = array($cacheKey, 'String');
     }
     CRM_Core_DAO::executeQuery($sql, $params);
   }
@@ -157,12 +157,12 @@ public function getSelection($cacheKey, $action = 'get') {
       $actionGet = ($action == "get") ? " AND is_selected = 1 " : "";
       $sql = "
 SELECT entity_id1, entity_id2 FROM civicrm_prevnext_cache
-WHERE cacheKey LIKE %1
+WHERE cacheKey = %1
       $actionGet
       $entity_whereClause
 ORDER BY id
 ";
-      $params[1] = array("{$cacheKey}%", 'String');
+      $params[1] = array($cacheKey, 'String');
 
       $contactIds = array($cacheKey => array());
       $cIdDao = CRM_Core_DAO::executeQuery($sql, $params);
@@ -199,7 +199,19 @@ public function getPositions($cacheKey, $id1, $id2) {
    * @param string $entityTable
    */
   public function deleteItem($id = NULL, $cacheKey = NULL, $entityTable = 'civicrm_contact') {
-    CRM_Core_BAO_PrevNextCache::deleteItem($id, $cacheKey, $entityTable);
+    $sql = "DELETE FROM civicrm_prevnext_cache WHERE  entity_table = %1";
+    $params = array(1 => array($entityTable, 'String'));
+
+    if (is_numeric($id)) {
+      $sql .= " AND ( entity_id1 = %2 OR entity_id2 = %2 )";
+      $params[2] = array($id, 'Integer');
+    }
+
+    if (isset($cacheKey)) {
+      $sql .= " AND cacheKey = %3";
+      $params[3] = array($cacheKey, 'String');
+    }
+    CRM_Core_DAO::executeQuery($sql, $params);
   }
 
   /**