Opened 13 years ago
Closed 11 years ago
#19564 closed enhancement (wontfix)
Helper function for getting/setting cache data
Reported by: | johnjamesjacoby | Owned by: | johnjamesjacoby |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.3 |
Component: | Cache API | Keywords: | has-patch |
Focuses: | Cc: |
Description
Most of the time when we want something from the object cache we go through a routine of: wp_cache_get(); checking a result; setting a default; setting the cache with wp_cache_set(); returning. Core should offer a neat way to do this all in one fell-swoop.
Attached patch is a proposed solution.
Attachments (1)
Change History (6)
#2
@
13 years ago
I'm particularly interested in how the callback parameter would work, knowing that generating a value to be cached would require various bits of information from the current context.
#4
@
11 years ago
- Owner set to johnjamesjacoby
- Status changed from new to assigned
Assigning to JJJ to ping him about this
#5
@
11 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from assigned to closed
I'm going to close this for now.
As scribu said many months ago, you probably require a lot of information about the current process. Such a callback would likely be a closure that passes in information from current scope and such. Which is not bad, but this also isn't a pattern I've seen in any other caching backend, at least ones with popular PHP libraries. get/set/add/increment/decrement/etc are all standard. Something along the lines of "attempt" is not.
You also typically do not want to set a cache value until after you have performed your work and are positive things are successful. This would make things much more difficult to catch, wait, etc. It's just a bit over-abstracted.
I've never needed to set a default when a cache value is not present.
Could you provide a usage example for the new function?