Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the documentation for the Cache component #6515

Closed
wants to merge 23 commits into from

Conversation

javiereguiluz
Copy link
Member

This fixes #6171.

This is WIP because there's more documentation to come ... but you can already review the proposed documentation. Thanks!

Now you can create, retrieve, updated and delete items using this cache pool::

// create a new item by trying to get it from the cache
$numProducts = $cache->getItem('stats.num_products');
Copy link
Contributor

Choose a reason for hiding this comment

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

The variable naming is confusing... What about $numProductsCacheItem?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch. I refactored this example before and forgot to update that part. It's updated now. Thanks.

@javiereguiluz
Copy link
Member Author

Update the docs for the cache items has been added. Next chapter: cache pools.

@javiereguiluz
Copy link
Member Author

Update in 599ed0a I've added an article about "Cache Pools". I have two questions:

  1. I don't know how to create cache pools. Please, someone share a snippet with me.

  2. What happens when you remove a cache item that doesn't exist? Do you get true as result?

Thanks!

@teohhanhui
Copy link
Contributor

It's also possible to override cache pools used by various Symfony services: #6171 (comment)

@javiereguiluz
Copy link
Member Author

@teohhanhui thanks ... but right now we are documenting the component. The integration with Symfony (and FrameworkBundle) will be documented later. So the question remains: how to create a cache pool with the Cache component?

@teohhanhui
Copy link
Contributor

@javiereguiluz:

What happens when you remove a cache item that doesn't exist? Do you get true as result?

From PSR-6:

If a Calling Library requests that one or more Items be deleted, or that a pool be cleared, it MUST NOT be considered an error condition if the specified key does not exist.

@teohhanhui
Copy link
Contributor

If by "cache pool" you mean Psr\Cache\CacheItemPoolInterface, then just instantiate the adapters...

On the other hand, cache pools as per the cache.pool DI tag are services processed by the compiler pass. They're conceptual. The actual instance is still one of the adapters.

@javiereguiluz
Copy link
Member Author

javiereguiluz commented Apr 26, 2016

Update: finished the first version of the doc for the Cache component.

@tgalopin @nicolas-grekas when you have some time, please review the docs of this PR and tell me what you think. After that, I'll write the docs about integrating Cache in Symfony framework. Thanks!

Cache Items
===========

Cache items are each one of the information units stored in the cache as a
Copy link
Member

Choose a reason for hiding this comment

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

Cache items are each one of the information units (or looks strange to me)

@unexge
Copy link

unexge commented May 22, 2016

maybe this case can be added as note to;

$cache = new FilesystemAdapter('foo', 3600);

$cacheItem = $cache->getItem('bar');

$cacheItem->set('baz');

// the cacheItem will not expire after 3600 seconds, it'll live forever
$cache->save($cacheItem);

// you need to call expiresAfter or expiresAt with null parameter if you want to use defaultLifetime
$cacheItem->expiresAfter(null);

// the cacheItem will expire after 3600 seconds
$cache->save($cacheItem);

.. note::

In Symfony applications this component is integrated (and enabled by
default) through the FrameworkBundle.
Copy link
Member

Choose a reason for hiding this comment

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

we don't have this note for other components as well, what about removing it here?

@nicolas-grekas
Copy link
Member

time to merge this one, features for 3.2 are coming :)

.. note::

Creating a cache item and setting its value is not enough to save it in the
cache. You must execute the ``save()`` method explicitly on the cache pool.
Copy link
Member

Choose a reason for hiding this comment

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

Why not showing this directly in the example above?

Copy link
Member

Choose a reason for hiding this comment

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

@javiereguiluz What do you think about this? Besides this to me this one is ready to be merged.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've implemented this change.

@eXtreme
Copy link
Contributor

eXtreme commented Jun 21, 2016

Finally merging something would be great because searching through these PRs, tests and DI config is not very helpful in understanding how to set it up correctly. AFAIR there even wasn't any "New in Symfony" article about this PSR6 cache.

@javiereguiluz
Copy link
Member Author

@eXtreme you are right. And the "New in Sf" article about the Cache is pending too.

@wouterj
Copy link
Member

wouterj commented Jun 26, 2016

Status: reviewed 👍

@javiereguiluz
Copy link
Member Author

I've made all the requested changes. I beg Doc Maintainers to merge this before someone else asks for more changes 😄 Thanks!

xabbuh added a commit that referenced this pull request Jun 30, 2016
…eguiluz)

This PR was submitted for the master branch but it was merged into the 3.1 branch instead (closes #6515).

Discussion
----------

Added the documentation for the Cache component

This fixes #6171.

This is WIP because there's more documentation to come ... but you can already review the proposed documentation. Thanks!

Commits
-------

6ddde65 Added the documentation for the Cache component
@xabbuh
Copy link
Member

xabbuh commented Jun 30, 2016

It took us some time. But now we are there. Thank you for writing the documentation, Javier!

@xabbuh xabbuh closed this Jun 30, 2016
@javiereguiluz javiereguiluz deleted the cache_component branch May 24, 2018 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation for the new PSR-6 Cache component
9 participants