At times we need to cache some values which are not related to Drupal config or data but are coming from external systems and which don't really need to be deleted when clearing (rebuilding) Drupal cache.

This module provides a way to use Drupal cache but still keep it separate from drush cr.

Code to use this new backend in your bin (here stock is just for example):

  cache.stock:
    class: Drupal\Core\Cache\CacheBackendInterface
    tags:
      - { name: cache.bin, default_backend: cache.backend.permanent_database }
    factory: cache_factory:get
    arguments: [stock]

Update1: Memcache support is added through pcb_memcache sub-module.

Update 2: [18th Sep, 2018] Memcache version alpha7 is supported now in release 1.1, support for future versions of memcache will be added as soon as BLT supports them. Feel free to create an issue for support of beta version or new versions of memcache. There is no change done or required in main module (which uses database to store cache).

Update 2: Redis is supported now, thanks to szantog

Update 3: Use the 2.x branch for memcache 2.x, module is completely D9 ready now.

FAQ

1. How to clear permanent cache through drush?
To clear permanent cache drush pcbf [bin] (e.g. drush pcbf stock)

2. How to clear permanent cache programmatically?
\Drupal::service('cache.stock')->deleteAllPermanent();

3. How to clear permanent cache through admin?
For each cache bin using pcb, there will be a button in Admin -> Development -> Performance page (admin/config/development/performance). Use them to clear cache for specific bins through Admin UI.

4. Will cache tags and cache expiration work?
Yes, everything works as is. Only difference is when we use drush cr or try to delete all cache entries.

5. How to know which cache bins are using permanent cache?
drush pcb-list

6. How to flush cache for all bins using permanent cache?
drush pcb-flush-all

--------------------

Supporting organizations: 

Project information

Releases