Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions en/appendices/3-5-migration-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,21 @@ behavior that may affect your application:
defaults alone.
* ``Cake\ORM\Table::addBehavior()`` and ``removeBehavior()`` now return
``$this`` to assist in defining table objects in a fluent fashion.
* Cache engines no longer throw an exception when they fail or are misconfigured,
but instead fall back to the noop ``NullEngine``. Fallbacks can also be
:ref:`configured <cache-configuration-fallback>` on a per-engine basis.

New Features
============

Cache
-----

* Cache engines can now be configured with a ``fallback`` key that defines a
cache configuration to fall back to if the engine is misconfigured (or
unavailable). See :ref:`cache-configuration-fallback` for more information on
configuring fallbacks.

Core
----

Expand Down
32 changes: 32 additions & 0 deletions en/core-libraries/caching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,38 @@ refer to the class name using the following syntaxes:
When using the FileEngine you might need to use the ``mask`` option to
ensure cache files are made with the correct permissions.

.. _cache-configuration-fallback:

Configuring Cache Fallbacks
---------------------------

In the event that an engine is not available, such as the ``FileEngine`` trying
to write to an unwritable folder or the ``RedisEngine`` failing to connect to
Redis, the engine will fall back to the noop ``NullEngine`` and trigger a loggable
error. This prevents the application from throwing an uncaught exception due to
cache failure.

You can configure Cache configurations to fall back to a specified config using
the ``fallback`` configuration key::

Cache::config('redis', [
'className' => 'Redis',
'duration' => '+1 hours',
'prefix' => 'cake_redis_',
'host' => '127.0.0.1',
'port' => 6379,
'fallback' => 'default',
Copy link
Member

@ravage84 ravage84 Jun 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious. What happens if one configures the same engine as fallback (e.g. by accident)? Do we have a clear exception for that? Something like "You are trying to configure the engine itself as its fallback"...

This would be a hard misconfiguration, something that SHOULD throw an exception, IMHO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty much exactly the exception it throws 😄 I did that exact thing while writing this haha

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahahaha, beautiful! 😆

]);

If the Redis server unexpectedly failed, writing to the ``redis`` cache
configuration would fall back to writing to the ``default`` cache configuration.
If writing to the ``default`` cache configuration *also* failed in this scenario, the
engine would fall back once again to the ``NullEngine`` and prevent the application
from throwing an uncaught exception.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you include a .. versionadded:: 3.5.0 admonition here for folks using older versions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes!


.. versionadded:: 3.5.0
Cache engine fallbacks were added.

Removing Configured Cache Engines
---------------------------------

Expand Down