Skip to content

Memory leak ? #529

@ftrudeau

Description

@ftrudeau

Configuration:

PhpFastCache version: 7.0.0-alpha
PHP version: 7.1.8
Operating system: Windows 10
Redis client : predis/predis v1.1.1

Remote Redis server: v=3.0.6 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=687a2a319020fa42

Issue description:

I've got this simple implementation, which is part of a PHP trait.

    /**
     * Return data from cache item
     *
     * @param $cache_key
     * @return mixed
     */
    public function cacheGet($cache_key)
    {

        $this->assetCacheAdapterExists();

        if ($item = $this->adapter->getItem($cache_key)) {

            if ($data = $item->get()) {

                Log::debug("MEMORY (cacheGet): " . (memory_get_peak_usage(true)/1024/1024));

                return $data;

            }

        }

        return false;

    }

    /**
     * Put stuff in cache
     *
     * @param $cache_key
     * @param $cache_data
     * @param $cache_tags
     * @param bool $cache_ttl
     * @return mixed
     */
    public function cachePut($cache_key, $cache_data, $cache_tags, $cache_ttl = false)
    {

        $this->assetCacheAdapterExists();

        if ($item = $this->adapter->getItem($cache_key)) {

            $expiresAfter = Carbon::now()->diffInSeconds($cache_ttl);

            $item->set($cache_data)->expiresAfter($expiresAfter);

            // Set cache tags
            foreach ($cache_tags as $tag) {

                $item->addTag($tag);

            }

            $this->adapter->save($item);

            Log::debug("MEMORY (cachePut): " . (memory_get_peak_usage(true)/1024/1024));
            
        }

    }

When memory usage appears in the logs, it keeps incrementing.

Not sure if my implementation is incorrect, or if there is a method I should call to reset some kind os state in the adapter

Any help would be greatly appreciated !

Thanks.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions