Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
First round of fixes
  • Loading branch information
javiereguiluz committed Apr 27, 2016
commit 6d21b01af4e4d5a53731dc427d4a7cdd20e808ff
33 changes: 18 additions & 15 deletions components/cache/cache_items.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Cache Items
===========

Cache items are each one of the information units stored in the cache as a
key/value pair. In the Cache component they are represented by the
Cache items are each of the information units stored in the cache as a key/value
Copy link
Member

Choose a reason for hiding this comment

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

I think "each of" can be removed?

pair. In the Cache component they are represented by the
:class:`Symfony\\Component\\Cache\\CacheItem` class.

Cache Item Keys and Values
Expand All @@ -18,13 +18,14 @@ identifier, so it must be unique for each cache pool. The PSR-6 standard limits
the key length to 64 characters, but Symfony allows to use longer keys (they are
encoded internally to reduce their size).
Copy link
Member

Choose a reason for hiding this comment

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

They are not encoded for all adapters but still the length is not limited. I suggest removing these brackets.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd advocate for keeping to 64 characters anyway, for interoperability (the whole point of PSR interfaces...)

Copy link
Member Author

Choose a reason for hiding this comment

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

If Symfony follows this 64-char limit internally and it doesn't enforce it externally, I think we should remove this information.

Copy link
Contributor

Choose a reason for hiding this comment

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

It does not matter what Symfony Cache does internally. The interface only guarantees that keys up to 64 characters will work. Say, the user swap out Symfony Cache for another PSR-6 cache, things might break if they go over that limit. And we should encourage users to stay within the limit - warn them of the risk of doing otherwise.


You can freely chose the keys, but they can only contain letters (A-Z, a-z),
You can freely choose the keys, but they should only contain letters (A-Z, a-z),
numbers (0-9) and the ``_`` and ``.`` symbols. Other common symbols (such as
``{``, ``}``, ``(``, ``)``, ``/``, ``\`` and ``@``) are reserved for future uses.
``{``, ``}``, ``(``, ``)``, ``/``, ``\`` and ``@``) are reserved by the PSR-6
standard for future uses.

The **value** of a cache item can be any data represented by a type which is
serializable by PHP, such as basic types (strings, integers, floats, boolean,
nulls), arrays and objects.
serializable by PHP, such as basic types (strings, integers, floats, booleans,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd remove all the "s" as a type enumeration.
Why not: [...] such as scalars (string, integer, float, boolean or null), arrays and objects.?

null), arrays and objects.

Creating Cache Items
--------------------
Expand Down Expand Up @@ -63,8 +64,9 @@ corresponding *getter* methods::
Cache Item Expiration
~~~~~~~~~~~~~~~~~~~~~

By default cache items are stored "permanently", which in practice means "as long
as allowed by the cache implementation used".
By default cache items are stored permanently. In practice, this "permanent
storage" can vary greatly depending on the type of cache being used, as
explained in the :doc:`/cookbook/cache/cache_pools` article.

However, in some applications it's common to use cache items with a shorter
lifespan. Consider for example an application which caches the latest news just
Expand Down Expand Up @@ -92,7 +94,8 @@ standard states that caching errors should not result in application failures.

In practice this means that the ``getItem()`` method always returns an object
which implements the ``Psr\Cache\CacheItemInterface`` interface, even when the
cache item doesn't exist. Therefore, you don't have to deal with ``null`` values.
cache item doesn't exist. Therefore, you don't have to deal with ``null`` return
values and you can safely store in the cache values such as ``false`` and ``null``.

In order to decide if the returned object is correct or not, caches use the
concept of hits and misses:
Expand All @@ -107,10 +110,10 @@ Cache item objects define a boolean ``isHit()`` method which returns ``true``
for cache hits::

$latestNews = $cache->getItem('latest_news');
$latestNews->expiresAfter(60);

// check the item a few seconds after creating it
$isHit = $latestNews->isHit(); // true

// check the item 10 minutes after creating it
$isHit = $latestNews->isHit(); // false
if (!$latestNews->isHit()) {
$news = //... do some heavy computation
Copy link
Member

Choose a reason for hiding this comment

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

the doc standard is:

// do some heavy computation $news = ...;
$cache->save($latestNews->set($news));
} else {
$news = $latestNews->get();
}
12 changes: 8 additions & 4 deletions components/cache/cache_pools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Array Cache Adapter
~~~~~~~~~~~~~~~~~~~

This adapter is only useful for testing purposes because contents are stored in
memory and no persisted in any way. Besides, some features explained later are
memory and not persisted in any way. Besides, some features explained later are
not available, such as the deferred saves::

use Symfony\Component\Cache\Adapter\ArrayAdapter;
Expand All @@ -45,7 +45,8 @@ Filesystem Cache Adapter
~~~~~~~~~~~~~~~~~~~~~~~~

This adapter is useful when you want to improve the application performance but
can't install in the server tools like APC or Redis::
can't install tools like APC or Redis in the server. This adapter stores the
contents as regular files in a set of directories on the local file system::

use Symfony\Component\Cache\Adapter\FilesystemAdapter;

Expand Down Expand Up @@ -74,7 +75,10 @@ APCu Cache Adapter

This adapter can increase the application performance very significantly, because
contents are cached in the memory of your server, which is much faster than the
Copy link
Member

Choose a reason for hiding this comment

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

in the shared memory

filesystem. It requires to have installed and enabled the PHP APC extension::
file system. It requires to have installed and enabled the PHP APC extension.
Copy link
Member

Choose a reason for hiding this comment

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

APCu extension (not APC), isn't it ?

It's not recommended to use it when performing lots of write and delete
operations because it produces fragmentation in the APCu memory and that
degrades performance significantly::
Copy link
Member

Choose a reason for hiding this comment

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

that can degrade


use Symfony\Component\Cache\Adapter\ApcuAdapter;

Expand All @@ -97,7 +101,7 @@ Redis Cache Adapter
This adapter, similarly to APCu adapter, can increase the application performance
very significantly, because contents are cached in the memory of your server. It
Copy link
Member

Choose a reason for hiding this comment

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

This description makes it as if Redis is like APCu (both store content "in the memory of your server").
But of course the difference is much more than that: Redis is accessed through network protocols, which means cached items can be shared by several PHP fronts, whearas APCu is accessed through shared memory, which is local to one single PHP server.

requires to have installed Redis and have created a connection that implements
``\Redis`` class::
the ``\Redis`` class::
Copy link
Member

Choose a reason for hiding this comment

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

Redis, RedisArray, RedisCluster or Predis are accepted now


use Symfony\Component\Cache\Adapter\RedisAdapter;

Expand Down