PHPSocialNetwork / phpfastcache

A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
https://www.phpfastcache.com
MIT License
2.36k stars 452 forks source link

Cloudflare - Cache Reserve R2 | Object Storage Driver #885

Closed dusta closed 1 year ago

dusta commented 1 year ago

What type of feature would you like?

Other (Please Specify)

The feature request

Cloudflare started implement Reserve Cache.

It would be a completely new type of drivers named "Object Storage Driver" You generate cache and send to R2/S3 and proxy server take this file cache

https://developers.cloudflare.com/cache/about/cache-reserve/ https://blog.cloudflare.com/r2-open-beta/

Code sample (optional)

No response

References (optional)

No response

Do you have anything more you want to share? (optional)

No response

github-actions[bot] commented 1 year ago

Hello curious contributor ! Since it seems to be your first contribution, make sure that you've been:

Geolim4 commented 1 year ago

Hello @dusta !

This is very interesting and I'll look into it for the next major (v10) or maybe minor release (v9.2).

Do you know if there any existing PHP SDK/Connector for Cloudflare Reserve Cache ?

Also I think will need to ask a "free" account to Cloudflare to make the initial development.

Thank for the suggestion !

dusta commented 1 year ago

@Geolim4 It's compatible with S3. Other problem is that you need to folow what files you have on server. To not spam Object Storage you need to use database to have information what files you alredy have and when should be updated.

Time ago I have wrote similar code for files S3 you can check here. https://github.com/dframe/fileStorage

I could even update the code to be compatibility as driver with phpfastcache but you would have to tell me if there is anything to get the tmp file cache


 /**
  * @param      $adapter
  * @param      $tmpName
  * @param      $filePath
  * @param bool $forcedUpdate
  *
  * @return array
  */
$Storage->put('s3', $tmpName, $filePath);
Geolim4 commented 1 year ago

Ohh okay, Phpfastcache is already supporting Firebase ATM, but S3 is some serious and complex architecture that I'm not a specialist at all. The level of abstraction required for Phpfastcache is high and to be honest at this moment I have no time to work on a new connector, especially a complex one like S3 :(

But if you want to implement it by yourself for your needs, Phpfastcache is extensible: https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV5%CB%96%5D-Extending-phpFastCache

Geolim4 commented 1 year ago

Also: https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV7%CB%96%5D-Override-a-core-driver-%7C-Setup-a-custom-driver

dusta commented 1 year ago

Thank you. I'll try to work on it.

Geolim4 commented 1 year ago

Hello, I'm closing this PR for now, If you need support again, ask to reopen it.

Cheers