# [VOTE] Add is_cacheable() stream-wrapper operation

- Thread: https://externals.io/message/81602
- Original archive: https://news-web.php.net/php.internals/81602
- Started by francois@tekwire.net on 2015-02-02T16:38:55+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #81602 — francois@tekwire.net — 2015-02-02T16:38:55+00:00

URL: https://externals.io/message/81602#81602

Hi,

Opening the vote for :

https://wiki.php.net/rfc/streams-is-cacheable

This RFC proposes a generic way for opcode caches to decide if a given URI
is cacheable or not.

Cheers

François

---

## #81608 — Rasmus Lerdorf — 2015-02-02T16:49:41+00:00

URL: https://externals.io/message/81602#81608 · In reply to: #81602

> Hi,
> 
> Opening the vote for :
> 
> https://wiki.php.net/rfc/streams-is-cacheable
> 
> This RFC proposes a generic way for opcode caches to decide if a given URI
> is cacheable or not.

Doesn't this imply that "path" is the one true cache key? There are some
issues with that which we will have to address at some point. For
example, when running fpm chrooted you need more than the path. We'll
likely need a more APC-like option here to use the device+inode for the
key. It seems like a generic mechanism like you are proposing needs to
take this into account and provide some mechanism that tells the opcode
cache how to determine uniqueness. Perhaps that is simply encoded into
the path parameter, but then maybe it should have a more appropriate name.

-Rasmus

---

## #81620 — francois@tekwire.net — 2015-02-02T17:31:11+00:00

URL: https://externals.io/message/81602#81620 · In reply to: #81608

> De : Rasmus Lerdorf [mailto:rasmus@lerdorf.com]
> Doesn't this imply that "path" is the one true cache key? There are some
> issues with that which we will have to address at some point. For
> example, when running fpm chrooted you need more than the path. We'll
> likely need a more APC-like option here to use the device+inode for the
> key. It seems like a generic mechanism like you are proposing needs to
> take this into account and provide some mechanism that tells the opcode
> cache how to determine uniqueness. Perhaps that is simply encoded into
> the path parameter, but then maybe it should have a more appropriate
> name.

Yes, it implies that the path is the cache key. It implies that the stream
wrapper has a way to build unique and reproducible paths (PHK, for instance,
builds a unique ID from (dev/inode/mtime) when opening a package and builds
its paths from this ID).

My first idea was to add a 'cache_key' element in the stream_stat() result.
This element would be a binary string to use as key. This way, the stream
wrapper can return a path, a dev/inode/mtime concatenation, etc. If we don't
want to modify the `stat()` result, we can define a 'cache_key' hook in
php_stream_wrapper_ops.

I reverted to a system where path is considered as unique because I thought
my original idea would be considered as too complex. And using the path as
key was enough for phar and phk. But I agree, it is not a good solution for
'file:', which should be cached  by dev/inode/mtime.

I put the vote in standby.

Cheers

François

---

## #81677 — David Muir — 2015-02-03T03:35:27+00:00

URL: https://externals.io/message/81602#81677 · In reply to: #81608

> 
> 
> > […]
> 
> Doesn't this imply that "path" is the one true cache key? There are some
> issues with that which we will have to address at some point. For
> example, when running fpm chrooted you need more than the path. We'll
> likely need a more APC-like option here to use the device+inode for the
> key. It seems like a generic mechanism like you are proposing needs to
> take this into account and provide some mechanism that tells the opcode
> cache how to determine uniqueness. Perhaps that is simply encoded into
> the path parameter, but then maybe it should have a more appropriate name.
> 
> -Rasmus
> 
> 

Don't we already have this problem with chrooted FPM? I haven't tested it more recently, but last time I tried, opcache would fail to invalidate the cache after updating the file. Worked fine with a non-chroot environment. Not sure if this is related to the issues you mean here...

---

## #81682 — Pierre Joye — 2015-02-03T06:40:17+00:00

URL: https://externals.io/message/81602#81682 · In reply to: #81620

>
> > […]
>
> Yes, it implies that the path is the cache key. It implies that the stream
> wrapper has a way to build unique and reproducible paths (PHK, for
instance,
> builds a unique ID from (dev/inode/mtime) when opening a package and
builds
> its paths from this ID).
>
> My first idea was to add a 'cache_key' element in the stream_stat()
result.
> This element would be a binary string to use as key. This way, the stream
> wrapper can return a path, a dev/inode/mtime concatenation, etc. If we
don't
> want to modify the `stat()` result, we can define a 'cache_key' hook in
> php_stream_wrapper_ops.

I am not a big fan of putting this info on the path. A path must remain a
path or URI, not some random generated string, requiring to be parsed to
get the actual path.

A cache key sounds cleaner, easier to implement and valid.

---

## #81727 — Rasmus Lerdorf — 2015-02-03T16:23:51+00:00

URL: https://externals.io/message/81602#81727 · In reply to: #81677

> 
> 
> > […]
> 
> Don't we already have this problem with chrooted FPM? I haven't tested it more recently, but last time I tried, opcache would fail to invalidate the cache after updating the file. Worked fine with a non-chroot environment. Not sure if this is related to the issues you mean here...

Yes, like I said, this is an issue we have to address still. It is on
the TODO list and definitely looking for volunteers. I just wanted to
make sure that Francois' RFC didn't introduce something which would make
it harder to eventually fix this by not allowing for a non-path cache key.

-Rasmus

---

## #81730 — francois@tekwire.net — 2015-02-03T19:02:17+00:00

URL: https://externals.io/message/81602#81730 · In reply to: #81727

> De : Rasmus Lerdorf [mailto:rasmus@lerdorf.com]
> > […]
> more recently, but last time I tried, opcache would fail to invalidate the cache
> after updating the file. Worked fine with a non-chroot environment. Not
> sure if this is related to the issues you mean here...
> 
> Yes, like I said, this is an issue we have to address still. It is on
> the TODO list and definitely looking for volunteers. I just wanted to
> make sure that Francois' RFC didn't introduce something which would make
> it harder to eventually fix this by not allowing for a non-path cache key.

Well, from what I see in accel_make_persistent_key_ex(), the key is the path or a concatenation of the path, the cwd, the include path... Of course, the idea is to avoid the `stat()` call. But I don't see how we can determine a reliable cache key without a `stat()`.

Maybe opcache shouldn't compute the key by itself. For each file it receives, it would ask the corresponding wrapper for a cache key (and the plain files wrapper would do a `stat()` and return dev/inode/mtime).

François
