On #2148255: [meta] Make better D8 api.d.o landing page, linked to high-level overview topics, and put it in Core api.php files, we made a patch that included a stub Topic page for api.drupal.org (i.e., a @defgroup) titled:
Cache API
This can be found in file core/modules/system/core.api.php where it says
@defgroup cache
The documentation to go on this page needs to be written. The idea is:
a) Write a few paragraphs about the topic.
b) Link to more detailed documentation on
https://drupal.org/developing/api/8
c) If the more detailed documentation does not yet exist, create stub page(s), link to the stub pages, and add a note to this issue stating that the stub pages need to be filled out.
d) If the topic has related classes, interfaces, and functions -- appropriate for an overview -- add
@ingroup cache
to their documentation headers. That will make these classes etc. show up on the Topic page on api.drupal.org. Only include classes/functions that are appropriate for an overview page please!
For more info -- documentation standards for @defgroup/@ingroup:
https://drupal.org/coding-standards/docs#defgroup
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2216543-18-cache_documentation.patch | 1.49 KB | eojthebrave |
| #6 | interdiff.txt | 9.05 KB | jhodgdon |
| #6 | cache-api-2216543-6.patch | 13.65 KB | jhodgdon |
| #5 | cache_api2.png | 408.21 KB | berdir |
| #5 | cache-api-2216543-5-interdiff.txt | 5.84 KB | berdir |
Comments
Comment #1
berdirStarting this..
There is some documentation on CacheBackendInterface right now, but this is a better place for it. Added some @section's, otherwise it's 1:1 copy. And while there's extensive documentation on how to configure a custom cache backend and deletion, there's nothing about the "normal usage".
Someone else is probably more qualified to start writing something there, so posting this as an intermediate step...
Comment #2
jhodgdonWow! Thanks! Great start!
A few things to fix:
a)
We don't actually want to lose that line. The first line after the { is for the one-line description of the defgroup (appears on Topics lists on api.d.o). So we should have something there.
b) Let's put @todo and a little summary of what should go into them, for the sections that still need to be written, like
c) I also think maybe we should change the order here, but maybe if the Basics section was filled in I wouldn't think so? :)
d) Since this is copy/pasted from an interface header, there are all kinds of references to class methods like:
These do not really make sense out of context -- probably need an interface or class name with them?
Comment #3
berdirc) I would assume that basics should come first, tags probably deserve their own section too.
d) True. But expanding that to Drupal\Core\Cache\CacheBackendInterface::delete() and so on would also be far less readable.
Comment #4
jhodgdonc) I was just a bit surprised to get to "Deletion" before I found out how to add stuff to the cache. But I think that would be covered in Basics hopefully/maybe, hence my "if Basics was filled in I wouldn't think [the order was wrong]". :)
d) The docs could say something like "The following methods are all on ...." and then just use the method names? Something like that would be fine. But having just methods there without any context, in a @defgroup doc, doesn't seem good. Keep in mind some people will not be reading the whole doc top to bottom either -- they will skim headers to find their information.
Comment #5
berdirOk, spent some more time on writing additional documentation and re-structuring a bit :)
Tried to address the feedback as much as possible, for d), I added a note about the location of the methods at the top, I don't think we should repeat that for every section?
Added a @todo's with issues that I know about that will affect ths.
Comment #6
jhodgdonI think the solution for (d) is fine, and this is looking pretty good -- thanks for all the writing!
I had a bunch of suggestions for how to make this documentation clearer (and there were some proofreeding changes that were also needed)... I decided the most efficient way to present them was by making a new patch. Hope that is OK. Please review carefully!
Note: I'm not sure an interdiff is all that useful... most of the core.api.php lines changed and nothing else changed. But I added one anyway.
Comment #7
berdirThanks, changes look good.
Comment #8
berdirAssigning to @webchick per @jhodgdon's suggestion, as she worked on it a bit too.
Comment #9
wim leersWill all of the code terms (function names and "cid") be wrapped in code tags?
I think that's essential for legibility of docs.
Comment #10
jhodgdonNo, we do not do that in documentation blocks normally.
Comment #11
wim leersAre there then at least plans to do so? It seems that since we have https://api.drupal.org/api/drupal/8, https://drupal.org/documentation will become less important, because most docs will live at https://api.drupal.org/api/drupal/8 instead. If none of that has the proper formatting, then that's a huge regression.
Comment #12
jhodgdonOn the contrary, the plan for the docs on api.drupal.org (the ones going into @defgroups) is that they are minimal summaries, and should link to sections of https://drupal.org/developing/api for more in-depth information.
Comment #13
webchickCommitted and pushed to 8.x. Thanks!
Comment #14
eojthebraveShoot. I was just about to add some comments to this one. Here they are:
This code seems wrong. We create the $cache object in the first line, but never use it. Then recreate it in the if statement. Seems like maybe the if statement should use $cache->get() instead? Lets make sure this is right and reflects best practices because people are going to copy/paste this example like crazy if it's in the docs.
It would be nice to have a better explination of why there are different cache bins and how I should decide when to use the default vs. another existing option vs. creating my own. Though perhaps this is something better for a handbook page? In which case we should create the stub of that page and link to it from here.
I find this a little confusing and think it would benefit from changing the order of statements. I think changing the backend of the entire system is likely more common than changing and individual bin. What about something like:
"By default cached data is stored in the database. This can be configured though so that all cached data, or that of an individual cache bin, uses a different cache backend, such as APC or Memcache, for storage."
I'm going to re-open this because at a minimum we should confirm that that code sample is correct. If it is and I'm just missing something feel free to tell me to stop being silly. :)
Comment #15
jhodgdonYes, please fix the code, that would be great! And if you can make a patch with better wording, that would also be great.
Comment #16
berdirthe only thing that's wrong about the code is the initial $cache definition, I forgot to remove that.
That is what I added the @todo to the re-organize cache bins issue (#1194136: Re-organise core cache bins). Documenting it right now not make sense as that issue will change a lot there.
Comment #17
jhodgdonWhen we fix this up a bit, could we also stress that doing $cache->get() doesn't give you your original data? Instead you have to do:
$cache = (get the Cache object)->get(...);
if ($cache) {
return $cache->data;
}
This code is correct in the example in the doc block, but this point is not stressed at all. Very confusing! (See #2225087: CacheBackendInterface->get() docs missing crucial information for an example of someone (me!) getting confused.)
Comment #18
eojthebraveHere's a patch that:
1. Removes the unnecessary $cache = line of code from the example.
2. Adds some clarification about the use of $cache->data & $data variables.
3. Rewords the paragraph in the configuration section that was a little bit confusing.
Thanks for taking care of that other @todo in #1194136: Re-organise core cache bins. I like that part now. :)
Comment #19
eojthebraveComment #20
berdirThanks, looks good. We have an issue to make the returned object a typed object with an interface/methods, but that got sidetracked on different things...
Comment #21
jhodgdonThanks! Agreed, it's good. Committed to 8.x.
Comment #22
jhodgdonComment #24
jhodgdon