PHPackages                             webandco/neos-asset-usage-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. webandco/neos-asset-usage-cache

ActiveNeos-package[Caching](/categories/caching)

webandco/neos-asset-usage-cache
===============================

Improve asset usage query performance

0.2(3y ago)05.1k↑333.3%1PHP

Since Nov 6Pushed 3y ago2 watchersCompare

[ Source](https://github.com/webandco/neos-asset-usage-cache)[ Packagist](https://packagist.org/packages/webandco/neos-asset-usage-cache)[ RSS](/packages/webandco-neos-asset-usage-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Asset Usage Cache
=================

[](#asset-usage-cache)

The package provides a strategy to cache the asset usage results. Additionally, the database query to fetch the related nodes is simplified and can be cached by the database server too.

Installation
------------

[](#installation)

Install the package with composer. It is recommended to use the package only in development environments.

```
composer require webandco/neos-asset-usage-cache

```

Features
--------

[](#features)

This package provides various features to improve performance of querying the asset usage.

The alternative package  also solves the performance problem using an elasticsearch index. The main differences to the elasticsearch package are:

1. This package, `webandco/neos-asset-usage-cache`, only needs the database you use for NEOS. There is no need for elasticsearch.
2. We assume the cache to be more short-lived, whereas the elasticsearch package is basically an index of the nodes and updated accordingly.
3. We also use a different method to inject our own `AssetUsageStrategy`. Via the Settings.yaml you can then disable/enable Strategies as you like. Thus you are more maneuverable and create add/extend your own `AssetUsageStrategy` - which is currently more complicated by default in NEOS.
4. You can disable the cache completely in `Settings.yaml` if you want and just enable it on purpose, e.g. in a long running command controller of yours.
5. You can also disable the cache itself and just let the database cache the results. This basically means that the query to determine the asset usage is modified. This approach can be very fast and provides correct results all the time. The drawback is that you need to reconfigure your database to increase query caches which can cause decreased query performance because of internal DB locks. More details and links down below.

### Configurable asset usage strategy

[](#configurable-asset-usage-strategy)

Currently the asset usage is generated by iterating over all classes implementing the `Neos\Media\Domain\Strategy\AssetUsageStrategyInterface`and sum up or merge the results from the implementations.

In a default setup, it is not possible to enable/disable strategies, making it more complicated to replace the current default strategy `Neos\Neos\Domain\Strategy\AssetUsageInNodePropertiesStrategy`

This package uses an aspect for `Neos\Media\Domain\Service\AssetService->getUsageStrategies()`and the configuration to disable or enable strategies. Thus one can easier add or remove an AssetUsageStrategy.

### Simplified database query

[](#simplified-database-query)

The default asset usage query in `AssetUsageInNodePropertiesStrategy` adds multiple LIKE conditions for the properties column to query the nodeData table.

The more an asset is in use, the more image variants exist, the more LIKE conditions are added and this slows the query down.

In this package we implemented an alternative approach, by just querying all rows which contain `__identifier` or `asset:` and then filter the results using PHP's preg\_match\_all. So the workload is moved away from the database and into PHP.

To make use of database query caching you likely need to increase query cache sizes, e.g.

```
SET GLOBAL query_cache_size = 500*1024*1024;
SET GLOBAL query_cache_limit = 200*1024*1024;

```

Keep in mind, that by increasing the database cache sizes, the database can actually be slowed down, see :

```
Be cautious about sizing the query cache excessively large,
which increases the overhead required to maintain the cache,
possibly beyond the benefit of enabling it.
Sizes in tens of megabytes are usually beneficial.
Sizes in the hundreds of megabytes might not be.

```

For futher details, see:

If you increase database query cache sizes, the query used in this package is cached, and there is no need for php caching.

### Cached asset usage

[](#cached-asset-usage)

The database result is managed via a cache, which is updated on signals for node changes and by default flushed every hour.

Performance
-----------

[](#performance)

The database query used in this package, takes around 4 sec for for around 300.000 nodes in the nodeData table. The more nodes the slower this query becomes.

This database query is independent of any given asset or usage count and performs the same for every asset.

If the cache is populated, the methods provided by `AssetUsageCacheStrategy`take around 6ms per asset nearly independent of the usage count.

Configuration
-------------

[](#configuration)

The default configuration, disables the `AssetUsageInNodePropertiesStrategy`and enables the provided `AssetUsageCacheStrategy`.

Additionally the queryCache is enabled and `realTimeUpdate` is enabled.

```
Webandco:
  AssetUsageCache:
    assetUsageStrategies:
      AssetUsageInNodePropertiesStrategy:
        className: 'Neos\Neos\Domain\Strategy\AssetUsageInNodePropertiesStrategy'
        disable: true
      AssetUsageCacheStrategy:
        className: 'Webandco\AssetUsageCache\Domain\Strategy\AssetUsageCacheStrategy'
        disable: false
    queryCache:
      disable: false
      realTimeUpdate: true

```

### Use cases

[](#use-cases)

#### Database query cache only

[](#database-query-cache-only)

To make use of the database query cache but not using the PHP cache, just disable the cache in the configuration

```
Webandco:
  AssetUsageCache:
    queryCache:
      disable: true

```

#### Enable cache on purpose

[](#enable-cache-on-purpose)

In case the cache should be not used in the media browser, but during a custom command line action, the cache needs to be disabled via configuration, see above.

In the command line action you can then enable the cache

```

    /**
     * @Flow\Inject
     * @var AssetCacheService
     */
    protected $assetCacheService;

....

    public function reConfigureAssetCache(){
        $this->assetCacheService->setRealTimeUpdate(false);
        $this->assetCacheService->setCacheDisabled(false);
        // eventually just flush the cache - globally
        $this->assetCacheService->flush();
    }

```

Thus the cache is used during the run of the current command line action which can be handy if you need to iterate over all assets and check their usage count.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~878 days

Total

2

Last Release

1141d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2139456?v=4)[web&amp;co](/maintainers/webandco)[@webandco](https://github.com/webandco)

---

Top Contributors

[![gjwnc](https://avatars.githubusercontent.com/u/19683930?v=4)](https://github.com/gjwnc "gjwnc (6 commits)")[![gradinarufelix](https://avatars.githubusercontent.com/u/4405087?v=4)](https://github.com/gradinarufelix "gradinarufelix (1 commits)")[![markuspfeifenberger](https://avatars.githubusercontent.com/u/7107293?v=4)](https://github.com/markuspfeifenberger "markuspfeifenberger (1 commits)")

### Embed Badge

![Health badge](/badges/webandco-neos-asset-usage-cache/health.svg)

```
[![Health](https://phpackages.com/badges/webandco-neos-asset-usage-cache/health.svg)](https://phpackages.com/packages/webandco-neos-asset-usage-cache)
```

###  Alternatives

[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)[cheprasov/php-redis-client

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1281.2M21](/packages/cheprasov-php-redis-client)[amphp/redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

165634.7k44](/packages/amphp-redis)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
