API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Cache%21C...

CacheableDependencyInterface::getCacheMaxAge() should document how to specify that a cache is permanent.

This is done by returning \Drupal\Core\Cache\Cache::PERMANENT.

Issue fork drupal-3296987

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joachim created an issue. See original summary.

anjali rathod’s picture

Assigned: Unassigned » anjali rathod
anjali rathod’s picture

@joachim Do we have to add the documentation in the API page?

cilefen’s picture

You do this in the code comment for getCacheMaxAge.

anjali rathod’s picture

Assigned: anjali rathod » Unassigned
yujiman85’s picture

Has this been resolved yet? I can make the change in the code comments for that function. As mentioned it looks like you can return Cache::Permanent to instantiate a non-expiring cache.

yujiman85’s picture

Assigned: Unassigned » yujiman85
cilefen’s picture

@Yujiman85 This documentation issue is open. It is not resolved.

yujiman85’s picture

Assigned: yujiman85 » Unassigned
Status: Active » Needs review
yujiman85’s picture

I have added the line to the comments for that function, it just needs to be reviewed to make sure it's clear what's being said.

cilefen’s picture

Status: Needs review » Needs work

I like the wording. Check over https://www.drupal.org/docs/develop/standards/api-documentation-and-comm... for format and style. In particular I noticed:

If you use a namespace on a class anywhere in documentation, always make sure it is a fully-qualified namespace (beginning with a backslash).

yujiman85’s picture

@cilefen Ah, my mistake. It's provided right in the description. I went ahead and made the change and pushed the commit.

yujiman85’s picture

Status: Needs work » Needs review
cilefen’s picture

Status: Needs review » Needs work

There is also this provision:

Lines containing comments (including docblocks) must wrap as close to 80 characters as possible without going over, with a few exceptions...

yujiman85’s picture

Status: Needs work » Needs review

Okay, I went ahead read that whole page to make sure I'm adhering to all the relevant rules. I made the change and hopefully this time it's good to go.

lucassc made their first commit to this issue’s fork.

lucassc’s picture

Hi, @Yujiman85! Thanks for commits.

I rebased MR's branch in order to make it synced up with 10.0.x. I also found out a little phpcs error but what's being said in documentation looks clear enough to me.

It's just a space left at the end of the line 49, now already removed:

FILE: ...rface-docs/web/core/lib/Drupal/Core/Cache/CacheableDependencyInterface.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 49 | ERROR | [x] Whitespace found at end of line
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 32ms; Memory: 8MB
gquisini’s picture

Assigned: Unassigned » gquisini

I'll be reviewing

gquisini’s picture

Assigned: gquisini » Unassigned
Status: Needs review » Reviewed & tested by the community

So,

Checking getCacheMaxAge() docblock, has the function and return description with fully qualified namespace.
Also, I rerun phpcs, but found no typos.

joachim’s picture

‘ instantiated’ doesn’t seem like the right word for caches.

yujiman85’s picture

@joachim I came up with some alternatives.

1) "An object may be cached indefinitely/permanently by returning ..."
2) "A non-expiring cache may be created by returning ..."
3) "To permanently cache an object, return ..."

joachim’s picture

Any of those is fine :)
Grammatically, 3 is simplest to read I think.

gquisini’s picture

Assigned: Unassigned » gquisini
Status: Reviewed & tested by the community » Needs work

Hi,
I'll work and edit that.

gquisini’s picture

Assigned: gquisini » Unassigned
Status: Needs work » Needs review

Ok,
Now the docblock looks like this:

The maximum age for which this object may be cached.
 
@return int
  The maximum time in seconds that this object may be cached.
  An object may be cached indefinitely/permanently by returning
  \Drupal\Core\Cache\Cache::PERMANENT.
yujiman85’s picture

@gquisini I should've clarified about the first one, that's my fault. I meant it to be either indefinitely OR permanently used in that statement instead of both with the slash. Or if the slash works for everybody then so be it.

diegors’s picture

Assigned: Unassigned » diegors
diegors’s picture

Assigned: diegors » Unassigned

Change the docblock to:

 @return int
    The maximum time in seconds that this object may be cached.
    An object may be cached permanently by returning
    \Drupal\Core\Cache\Cache::PERMANENT.

Needs review.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

Looks great! Thanks!

alexpott’s picture

Version: 10.0.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 45ec97a437 to 10.1.x and b8a5da0a68 to 10.0.x and d70f1b040d to 9.5.x. Thanks!

Backported to 9.5.x as a docs improvement

  • alexpott committed 45ec97a on 10.1.x
    Issue #3296987 by Yujiman85, lucassc, gquisini, diegors, joachim,...

  • alexpott committed b8a5da0 on 10.0.x
    Issue #3296987 by Yujiman85, lucassc, gquisini, diegors, joachim,...

  • alexpott committed d70f1b0 on 9.5.x
    Issue #3296987 by Yujiman85, lucassc, gquisini, diegors, joachim,...
alexpott’s picture

Version: 9.5.x-dev » 9.4.x-dev

Discussed with @longwave we agreed to backport this 9.4.x
Committed bb633d6 and pushed to 9.4.x. Thanks!

  • alexpott committed bb633d6 on 9.4.x
    Issue #3296987 by Yujiman85, lucassc, gquisini, diegors, joachim,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.