PSR-6 and PSR-16 bridge
IndraGunawan opened this issue ยท 6 comments
i think its good if reactphp/cache
has bridge to PSR-6 (Caching Interface) and PSR-16 (Simple Cache)
what do you think?
I'm currently of the opinion React shouldn't adopt either PSR cache interface.
The purpose of PSRs is for implementation interoperability. Since these PSRs are most often going to be I/O bound a likely scenario that would happen is a React lib accepts a PSR cache interface and the implementation chosen by the developer is blocking.
Is it the developers fault for choosing a non-compatible implementation even though they used the correct interface or is it React's fault for allowing it? I think the latter.
Given the nature of NBIO I think it's better we have our own cache interface that is more explicit, returning a Promise on a cache read.
nice, i got it
I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can reopen this ๐
I think something like this would be good idea. The fact that PSR-6 specifies about deferred methods and manual commits would be useful for libraries that deal with so many I/O operations.
I would not expect it fully asynchronous or conflicting with blocking codes, maybe hybrid ones would do.
My use case is DiscordPHP, running a Discord bot that can online for 24/7, mostly powered by ReactPHP.
Our users (bot creators depending on our library) are facing issues with running out memories (especially being on large server) since we only implemented in-memory caching until we found this library. In hope that users can choose between reactphp/cache implementation such as FileSystem, Redis, Memcached on their own. Besides of memory issue, the goal is also for scalability.
I as one of the library developer struggles rewriting our library code that extensively deals with set/get data in one scope. While reactphp/async library comes for a little help, but that still worry me how extensive the interface calls would also interrupt the main bot connection and operation (we start noticing lost connection & reconnect attempts).
I have a thought that if the PSR-6-like exists for reactphp/cache (or as separate package), it would allow us to temporary process data in memory for extensive I/O and choose when to commit / save deferred the data to the cache interface & cache pool to release the PHP memory usage.
But unfortunately I guess for now we are not getting one sooner, instead we go away from interoperability and had to implement our own caching mechanism/wrapper.
So react/cache
is method wise on par with PSR-16. But it returns a promise instead. With react/async
now out, I've started working on a package for that: WyriHaximus/reactphp-cache-psr-16-adapter#1
@SQKo FYI: I've tagged a release on https://github.com/WyriHaximus/reactphp-cache-psr-16-adapter