CloudFlare CDN Edge Worker Full Page Cache(FPC) Microservice Layer for Magento 2 and Shopify
GPL-3.0 License
CloudFlare(CF) CDN Worker Full Page Cache(FPC) Layer for Magento 2. It has become true. Now, it is Open Source and free. The original idea was the Shopify FPC cache from the CloudFlare CDN, and it was part of our true Magento SaaS solution(Magneto)
The Edge Worker Magento full-page cache feature helps you optimize eCommerce performance by caching your Magento backend server's generated HTML or API response.
CF Edge Worker Magent Full-page cache intercepts incoming requests and checks if a cached version of the requested content is available in the CloudFlare locations or in the cache Reserve. This check for the cached version can have the following outcomes, depending on its state:
CF Worker “softpurge” the cache by changing cache Version stored in the KV(Key Value)storage. Cloud flare serve the stale content untill it will not be updayed asynchronously (in the background) fetches the new page. Cloud Front ignores any cache rules from Magento and has own logic which serve web pages from the CDN cache even if Magento 2 website is broken.
For CF FPC Worker to consider a response from a Magento backend as cacheable, the response must meet the following criteria:
Open Cloud Flare and Go to Workers
It is better to Upgrade the plan to a Bundle of 5$ per month. It is better and has no limitations.
Bundle:
Workers features Includes 10 million requests per month 3
Up to 50ms CPU time per request Always lowest latency Key-value storage features 4 10 million read operations per month 1 million write, delete, list operations per month
Workers & Pages -> KV -> Create a namespace
Workers & Pages -> Overview -> Create -> Create Worker -> Deploy
Edit Code -> Insert Code From the Git
Worker Variable name must be EDGE_CACHE. KV name doesn't matter (Select from the drop-down)
Configure the OTHER_HOST (for example, google.com) variable to test workers through the worker domain. This will replace the worker domain with your staging or prod domain, and the server response will be fetched from there.
Done! Test it using Dev Console.
You can also exclude some page rules, such as static and media, from workers. It will save money on request.
Also, Enable CF Cache Reserve to increase edge cache HIT rate. To reduce CF costs, you can exclude media and static from the cache reserve. However, cache reserve is a nice stuff, and you can benefit from storing images in it.
Disable Cloud Flare Chache for Static and Media save and serve from the Cache Reserve <be > Caching -> Cache Rules
Add Rule
Expression :
(http.request.full_uri wildcard "*.site.com/static/*") or (http.request.full_uri wildcard "*.site.com/media/*"
Replace site with your <br>
Please update this documentation when you will do it yourself. It is just a fast-written manual. For detailed information, check the Worker code.
If you have any issues, create an issue or email me: egorshitikov[A]gmail.com
We also developed a Magento Extension designed to enhance communication and performance between CF Workers and the cache system. <br> While this extension is not yet publicly available, feel free to contact me directly if you’re interested in receiving it.
You can add any cookies you want just by changing the script.
Cache Reserve is a large, persistent data store implemented on top of CF R2. Your website’s cacheable FPC content will be written to Cache Reserve. Cache Reserve serves as the ultimate upper-tier cache, reserving storage space for your FPC for as long as you want. This ensures that your FPC is served from the cache. Cache Reserve is a CF feature that allows the use of Claud Flare as a main cache solution.
Like the standard CDN, Cache Reserve also uses the cf-cache-status header to indicate cache statuses like MISS, HIT, and REVALIDATED. Cache Reserve cache misses and hits are factored into the dashboard’s cache hit ratio.
Individual sampled requests that were filled or were served by Cache Reserve are viewable via the CacheReserveUsed Logpush field.
Cache Reserve monthly operations and storage usage are viewable in the dashboard.
With the CF FPC Workers, you can achieve 91%+ page cache rate from CDN
Open the page. Check Cf-Cache-Status header.
Timing: Server response time must be less than 60ms.