Remove old/invalid keys
does not remove recently used ones (for proper feedback)!

@return int Rows
544433
public function garbageCollector() {
		$conditions = [
			$this->getAlias() . '.created <' => date(FORMAT_DB_DATETIME, time() - $this->validity),
		];
		return $this->deleteAll($conditions);
	}
21553
public static function cleanupRemovedItems()
    {
        $db = eZDB::instance();
        // Find items that have been moved to trash or deleted
        $itemArray = array();
        $offset = 0;
        $limit = 50;
        do
        {
            $items = $db->arrayQuery( 'SELECT node_id FROM ezm_pool', array( 'offset' => $offset, 'limit' => $limit ) );
            if ( empty( $items ) )
                break;

            foreach( $items as $item )
            {
                $rows = $db->arrayQuery( 'SELECT node_id FROM ezcontentobject_tree WHERE node_id = ' . $item['node_id'] );
                if ( empty( $rows ) )
                    $itemArray[] = $item['node_id'];
            }

            $offset += $limit;
        } while ( true );

        // Remove them all from the flow
        $itemArrayCount = count( $itemArray );
        if ( $itemArrayCount > 0 )
        {
            $db->begin();
            $db->query( 'DELETE FROM ezm_pool WHERE ' . $db->generateSQLINStatement( $itemArray, 'node_id' ) );
            $db->commit();
        }

        return $itemArrayCount;
    }
910007
def clear
      invalid_keys = all_keys.select { |key| key.include?(@scope.table_name.downcase) }
      invalid_keys.each { |key| Rails.cache.delete(key) }

      Rails.cache.write(list_key, all_keys - invalid_keys)
    end
849908
protected function _toArrayWithoutPrimaryKeys()
    {
        $ret = $this->toArray();
        unset($ret[$this->getModel()->getPrimaryKey()]);
        foreach ($this->_getSiblingRows() as $r) {
            $primaryKey = $r->getModel()->getPrimaryKey();
            if ($primaryKey) {
                unset($ret[$primaryKey]);
            }
        }
        return $ret;
    }
441697
protected static function _cleanPrevious()
		{
			if(self::$_cleanedPrev) return true;
			self::$_cleanedPrev = 1;

			if(isset($_SESSION) && is_array($_SESSION)) {
                foreach ($_SESSION as $key => $value) {
                    if (strpos($key, self::$_sessionKey) === 0) {
                        if ($_SESSION[$key][0] < 1) {
                            unset($_SESSION[$key]);
                        } else {
                            $_SESSION[$key][0] = 0;
                        }
                    }
                }
            }
		}
184003
private function flushDeletes()
    {
        $ids = array();
        foreach ($this->bulkDeleteRecords as $record) {
            $ids[] = $record->Id;
        }

        $result = $this->client->delete($ids);
        $this->bulkDeleteRecords = array();

        return $result;
    }
153740
public function actionCleanup()
    {
        $tagIds = Tag::find()->select(['id'])->column();

        $batch = TagRelation::find()->batch();
        $i = 0;
        $delete = 0;
        foreach ($batch as $rows) {
            foreach ($rows as $relation) {
                $i++;
                // check if tag id exists in table
                if (!in_array($relation->tag_id, $tagIds)) {
                    $relation->delete();
                    $delete++;
                    continue;
                }

                $prefixedTableName = '{{%'.$relation->table_name.'}}';
                $pk = $this->tableSchema($prefixedTableName)->primaryKey;
                $query = (new Query())
                    ->from($prefixedTableName)
                    ->where([current($pk) => $relation->pk_id]) // provide model mapping or read pk name from schema
                    ->exists();

                if (!$query) {
                    $relation->delete();
                    $delete++;
                }

                unset($relation, $prefixedTableName, $pk, $query);
            }
        }

        return $this->outputSuccess("{$i} items checked and {$delete} items deleted.");
    }
800989
public function invalidate()
    {
        $query = $this->pdo->prepare(<<<SQL
DELETE FROM robotstxt__cache1
WHERE base = :base;
SQL
        );
        $query->bindValue('base', $this->base, \PDO::PARAM_STR);
        return $query->execute();
    }
638565
public function purge() {
        if ($this->isready) {
            $files = glob($this->glob_keys_pattern(), GLOB_MARK | GLOB_NOSORT);
            if (is_array($files)) {
                foreach ($files as $filename) {
                    @unlink($filename);
                }
            }
            $this->keys = array();
        }
        return true;
    }
1025304
public function pop()
    {
        if ($this->count() == 0) {
            return null;
        }
        $ret = $this->getLast();
        $lastKey = $this->getInternalIterator()->key();
        $this->offsetUnset((string) $lastKey);

        return $ret;
    }
337071
public function delete()
    {
        $where = $this->_getWhereQuery();

        /**
         * Execute the DELETE (this may throw an exception)
         */
        $result = $this->_getTable()->delete($where);

        /**
         * Reset all fields to null to indicate that the row is not there
         */
        $this->_data = array_combine(
            array_keys($this->_data),
            array_fill(0, count($this->_data), null)
        );

        return $result;
    }
992949
public function clear()
    {
        $keys = self::$instance->keys($this->options['prefix'].'*');
        if ($keys) {
            self::$instance->del(...$keys);
        }

        return true;
    }
804454
protected static function clear_old_records() {
        global $DB;

        $sql = "SELECT dpctx.*
                  FROM {tool_dataprivacy_ctxexpired} dpctx
             LEFT JOIN {context} ctx ON ctx.id = dpctx.contextid
                 WHERE ctx.id IS NULL";

        $orphaned = $DB->get_recordset_sql($sql);
        foreach ($orphaned as $orphan) {
            $expiredcontext = new expired_context(0, $orphan);
            $expiredcontext->delete();
        }

        // Delete any child of a user context.
        $parentpath = $DB->sql_concat('ctxuser.path', "'/%'");
        $params = [
            'contextuser' => CONTEXT_USER,
        ];

        $sql = "SELECT dpctx.*
                  FROM {tool_dataprivacy_ctxexpired} dpctx
                 WHERE dpctx.contextid IN (
                    SELECT ctx.id
                        FROM {context} ctxuser
                        JOIN {context} ctx ON ctx.path LIKE {$parentpath}
                       WHERE ctxuser.contextlevel = :contextuser
                    )";
        $userchildren = $DB->get_recordset_sql($sql, $params);
        foreach ($userchildren as $child) {
            $expiredcontext = new expired_context(0, $child);
            $expiredcontext->delete();
        }
    }
198060
public function clear()
    {
        if (isset($this->config[ 'dbIndex' ])) {
            return $this->redis->flushDB();
        } else {
            return $this->redis->flushAll();
        }
    }
1034443
public function delete(): int
    {
        $pdoStatement = $this->provideStatement();
        $pdoStatement = $this->execute($pdoStatement);
        return $pdoStatement->rowCount();
    }
429370
public function removeActionErrors(...$keys) {
        $errors = $this->getAttribute(ACTION_ERRORS_KEY);
        $dropped = [];

        foreach ($keys as $key) {
            if (isset($errors[$key]))
                $dropped[$key] = $errors[$key];
            unset($this->attributes[ACTION_ERRORS_KEY][$key]);
        }
        if ($keys)
            return $dropped;

        unset($this->attributes[ACTION_ERRORS_KEY]);
        return $errors;
    }
575047
private function cleanExpired()
    {
        // 10% chance to clean the database of expired sessions
        if (mt_rand(1, 10) == 1) {
            $expiredTime = $this->now - $this->secondsUntilExpiration;
            $stmt = $this->db->prepare("DELETE FROM {$this->tableName} WHERE time_updated < {$expiredTime}");
            $stmt->execute();
        }
    }