Problem/Motivation

In drupal 7 one could consume cache binaries on the fly without having to declare them anywhere:

cache_get(cid, 'whatever');

If you try to do the same thing in Drupal 8, you get a service not found exception:

\Drupal::cache('whatever')->get($cid);

Yes you can still retrieve the cache factory service and ask for a binary.... but that's cumbersome. The first time you get this exception it's a WTF as to why should I explictly have to create a service for each binary.

Proposed resolution

Try to find the cache service, and if it does not exist, fallback to using the cache_factory service to request a binary.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

david_garcia created an issue. See original summary.

david_garcia’s picture

Issue summary: View changes
david_garcia’s picture

Let's try with this patch.

Indeed, the documentation for cache() is confusing as it does not mention anywhere that you need a service per binary to make this work.

david_garcia’s picture

Issue summary: View changes
dawehner’s picture

Status: Active » Needs review

.

Status: Needs review » Needs work

The last submitted patch, 3: 2662072-drupal-cache.patch, failed testing.

david_garcia’s picture

Status: Needs work » Needs review
FileSize
1.22 KB

Status: Needs review » Needs work

The last submitted patch, 7: 2662072-drupal-cache.patch, failed testing.

Berdir’s picture

Status: Needs work » Closed (works as designed)

This is by design IMHO, we use the services to clear them up on uninstall.

Not sure what a use case for this would be, it's easy to use a single cache bin and cache tags to make invalidation on a set of entries easy.

We also use a single cache bin for the storage of all entity types, unlike 7.x entitycache module.

Please update if you think you have a valid use case.