Unset an object from the cache in one fell swoop

@param \stdClass $object        The object to remove from the cache
@param bool      $clearCacheDir Whether to clear the cache directory or not
541237
protected function unsetCacheObject($object, $clearCacheDir = true)
    {
        $objectId       = isset($object->id) ? $object->id : '';
        $objectFilename = isset($object->file->name->disk) ? $object->file->name->disk : '';
        $bucketId       = isset($object->bucket->id) ? $object->bucket->id : '';
        $bucketSlug     = isset($object->bucket->slug) ? $object->bucket->slug : '';

        // --------------------------------------------------------------------------

        $this->unsetCache('object-' . $objectId);
        $this->unsetCache('object-' . $objectFilename);
        $this->unsetCache('object-' . $objectFilename . '-' . $bucketId);
        $this->unsetCache('object-' . $objectFilename . '-' . $bucketSlug);

        // --------------------------------------------------------------------------

        //  Clear out any cache files
        if ($clearCacheDir) {

            // Create a handler for the directory
            $pattern = '#^' . $bucketSlug . '-' . substr($objectFilename, 0, strrpos($objectFilename, '.')) . '#';
            $fh      = @opendir(static::CACHE_PATH);

            if ($fh !== false) {

                // Open directory and walk through the file names
                while ($file = readdir($fh)) {

                    // If file isn't this directory or its parent, add it to the results
                    if ($file != '.' && $file != '..') {

                        // Check with regex that the file format is what we're expecting and not something else
                        if (preg_match($pattern, $file) && file_exists(static::CACHE_PATH . $file)) {
                            unlink(static::CACHE_PATH . $file);
                        }
                    }
                }
            }
        }
    }
1049025
static function clearAll( $cacheList = false )
    {
        if ( !$cacheList )
            $cacheList = eZCache::fetchList();

        foreach ( $cacheList as $cacheItem )
        {
            eZCache::clearItem( $cacheItem );
        }
        return true;
    }
1271760
public function clear($class, $method)
    {
        $cache_path = $this->config->get('cache_path');

        // we know which one we're clearing
        if ($method) {
            $directory = $this->_prep_path($class, $method);

            return (bool) $this->_delete_dir($cache_path.$directory);
        } else {
            // we're clearing everything for this class
            $directory = $this->_prep_path($class);

            return (bool) $this->_delete_dir($cache_path.$directory);
        }
    }
1048090
public function remove($object)
    {
        // create property accessor
        $accessor = PropertyAccess::createPropertyAccessor();

        // delete existing documents with same id
        foreach ($this->index->find('id:' . $accessor->getValue($object, 'id')) as $hit) {
            $this->index->delete($hit->id);
        }
    }
536408
public static function ClearCache($CacheName = FALSE) {
      Gdn_Autoloader::SmartFree();
      if ($CacheName != 'locale') return;
      
      if (!array_key_exists($CacheName,self::$Caches))
         return self::PrepareCache($CacheName);
      
      $UseCache = (Gdn::Cache()->Type() == Gdn_Cache::CACHE_TYPE_MEMORY && Gdn::Cache()->ActiveEnabled());
      if ($UseCache) {
         $CacheKey = sprintf(Gdn_LibraryMap::CACHE_CACHE_NAME_FORMAT, $CacheName);
         $Deleted = Gdn::Cache()->Remove($CacheKey);
      } else {
         @unlink(PATH_CACHE.DS.self::$Caches[$CacheName]['ondisk']);
      }
      self::$Caches[$CacheName]['cache'] = array();
   }
985620
public function delete($object)
    {
        $ret = $this->getValidator()->validateDelete($object);
        if ($ret) {
            $ret = $this->_delete($object);
        }
        return $ret;
    }
661886
public function removeObject(DataObject $object)
    {
        $item = ChangeSetItem::get()->filter([
            'ObjectID' => $object->ID,
            'ObjectClass' => $object->baseClass(),
            'ChangeSetID' => $this->ID
        ])->first();

        if ($item) {
            // TODO: Handle case of implicit added item being removed.

            $item->delete();
        }

        $this->sync();
    }
273782
public function remove($object)
    {
        $this->hasUnpersistedChanges = true;
        if ($this->addedObjects->contains($object)) {
            $this->addedObjects->detach($object);
        } else {
            $this->removedObjects->attach($object);
        }
    }
1330831
final protected function deleteObjectFromCache(Model $object)
    {
        $uniqueIdentifier = $object->UniqueIdentifier;

        if ($uniqueIdentifier === null) {
            return;
        }

        if (isset($this->cachedObjectData[$uniqueIdentifier])) {
            unset($this->cachedObjectData[$uniqueIdentifier]);
        }
    }
775279
public function offsetUnset($object) : void
    {
        $hash = spl_object_hash($object);

        unset($this->objects[$hash]);
        unset($this->data[$hash]);
    }
1124160
protected function cleanCache()
    {
        if ($this->cleanCount < 1) {
            ++$this->cleanCount;
            if (is_object($this->phpCache)) {
                $this->phpCache->clean();
            }
        }
    }
254367
public static function cache_set($key, $object) {
		$handler = '\Skeleton\Object\Cache\Handler\\' . Config::$cache_handler;
		$handler::set($key, $object);
	}
1116416
protected function doRestore($object): void
    {
        $changeSet = $this->uow->getObjectChangeSet($object);
        $ref = new \ReflectionClass($object);

        foreach ($changeSet as $field => $values) {
            $fv = new FieldVote($object, $field);

            if ($this->isRestoreViewGranted($fv, $values)) {
                $property = $ref->getProperty($field);
                $property->setAccessible(true);
                $property->setValue($object, $values['old']);
            }
        }
    }
287405
public function unref(?int $object): void
    {
        if (isset($this->protocol)) {
            $this->protocol->writeUnref($object);
        }
    }
110526
public function removeObject($object)
    {
        $oid = spl_object_hash($object);
        $data = [];
        if (isset($this->objectsRepository[$oid])) {
            $repository = $this->objectsRepository[$oid];
            $data = $repository->getHydrator()->unhydrate($object);
        }
        $id = isset($data['_id']) ? serialize($data['_id']) . $repository->getCollection() : $oid;

        if (!isset($this->objectStates[$id])) {
            throw new Exception\StateException("Can't remove object, it does not be managed");
        }

        unset($this->objectStates[$id]);
        unset($this->objects[$id]);
        unset($this->objectsRepository[$id]);
        unset($this->objectStates[$oid]);
        unset($this->objects[$oid]);
        unset($this->objectsRepository[$oid]);
    }
336308
public static function clear_static_caches() {
        global $DB;
        // Do not use get/set config here because the caches cannot be relied on.
        $record = $DB->get_record('config', array('name'=>'scheduledtaskreset'));
        if ($record) {
            $record->value = time();
            $DB->update_record('config', $record);
        } else {
            $record = new \stdClass();
            $record->name = 'scheduledtaskreset';
            $record->value = time();
            $DB->insert_record('config', $record);
        }
    }
1006525
public function delete($object, $flush = true)
    {
        try {
            $entityManager = $this->getEntityManager($object);
            $this->preDelete($object);
            $entityManager->remove($object);
            if ($flush) {
                $entityManager->flush();
            }
            $this->postDelete($object);
        } catch (\PDOException $e) {
            throw new ModelManagerException('', 0, $e);
        }
    }