HTML Cache
matiasfuster opened this issue · 16 comments
Any advances on the html file caching? How would you implement this? I can try doing it if it still needed.
@bramstroker any update on this project?
@matiasfuster did you do something about this feature?
@stefanorg well I didn't use this, I ended up doing it my self as you can see here and here and here and here and here and here the config
@stefanorg I did some work for this a while ago, I think I got the functionality working, but I'm not 100% sure. Docs are missing, so I need to write those. Will set a note in my agenda to have a look into it soon, busy schedules.. deadlines.. you know :-(
@bramstroker taking a look at the code i tried this way:
'strokercache' => [
'storage_adapter' => [
'name' => \StrokerCache\Storage\Adapter\File::class,
'options' => [
'base_directory' => __DIR__ . "/../../public/fpc"
]
],
'strategies' => [
'enabled' => [
'StrokerCache\Strategy\RouteName' => [
'routes' => [
'home'
],
]
]
]
]
Actually an html file were created in public/fpc but it has md5 name.
Using part of the provided .htaccess.dist
i'm able to access at the url http://base_url/md5_encoded_file_name
I don't know if i'm in the right way ...
@matiasfuster i'm taking a look at your code, i saw that it generate *.html file on filesystem but how it's served? did you modify your .htaccess ? Or the only way to access the cached data is throgh the CacheListener?
@bramstroker I just added a rewrite rule to my htaccess, if the file exists in cache it just serves it witheven running php which speeds up everthing. All you have to do is work in your cache invalidation strategy.
@matiasfuster ok just got it i saw this in you htaccess
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} ^/(espanol|english|portugues)/(.+)-(\d+)$
#RewriteCond %{DOCUMENT_ROOT}/pages/%1/%3\.html -f
#RewriteRule ^(.*)$ /pages/%1/%3\.html [NC,L]
Ok, this way the bootstrap process is not triggered, but how to, just you said, regenerate the file? how to invalidate the cache?
Well that depends on what technically invalidates the page for you. In our case the page content is generated by an administration panel, when we do changes to content, we invalidate the page that contains those contents. In our case the invalidation consists in deleting the pageId.html file.
ok it was as i thought, but it's better to ask :) 👍
no problem! if you need further help just ping me
👍 thank you!
@stefanorg . Could you try two things?
Set the configuration to use another id generator:
'strokercache' => array(
'id_generator' => 'fullUri'
),
Now alter the id generator and remove the md5 call.
The File adapter should not rely on md5 keys and I think this is where the bug is. When the hotfix works I have to figure out a clean solution to use another id generator when you choose the File adapter.
The File adapter you already configured is the correct one for the apache implementation.
When you call for example http://foo.bar/test/mypage/ the following folder structure should be created: fileroot/http/foo.bar/test/mypage.
This should work nice in combination with the distributed htaccess files
Let me know if you have any progress.
@bramstroker i'm playing around i'll let you know, i had problem with the scheme
and host
part of the uri that is not set, for instance calling http://myapp.dev.local
those are not set....
i suppose because i was using the RequestUriGenerator ...
@bramstroker using the fullUri
is ok, but why the page still have this on top of the generate file:
O:33:"Zend\Http\PhpEnvironment\Response":8:{s:10:"*version";N;s:14:"*contentSent";b:0;s:27:"*recommendedReasonPhrases";a:57:{i:100;s:8:"Continue";i:101;s:19:"Switching Protocols";i:102;s:10:"Processing";i:200;s:2:"OK";i:201;s:7:"Created";i:202;s:8:"Accepted";i:203;s:29:"Non-Authoritative Information";i:204;s:10:"No Content";i:205;s:13:"Reset Content";i:206;s:15:"Partial Content";i:207;s:12:"Multi-status";i:208;s:16:"Already Reported";i:300;s:16:"Multiple Choices";i:301;s:17:"Moved Permanently";i:302;s:5:"Found";i:303;s:9:"See Other";i:304;s:12:"Not Modified";i:305;s:9:"Use Proxy";i:306;s:12:"Switch Proxy";i:307;s:18:"Temporary Redirect";i:400;s:11:"Bad Request";i:401;s:12:"Unauthorized";i:402;s:16:"Payment Required";i:403;s:9:"Forbidden";i:404;s:9:"Not Found";i:405;s:18:"Method Not Allowed";i:406;s:14:"Not Acceptable";i:407;s:29:"Proxy Authentication Required";i:408;s:16:"Request Time-out";i:409;s:8:"Conflict";i:410;s:4:"Gone";i:411;s:15:"Length Required";i:412;s:19:"Precondition Failed";i:413;s:24:"Request Entity Too Large";i:414;s:20:"Request-URI Too Long";i:415;s:22:"Unsupported Media Type";i:416;s:31:"Requested range not satisfiable";i:417;s:18:"Expectation Failed";i:418;s:12:"I'm a teapot";i:422;s:20:"Unprocessable Entity";i:423;s:6:"Locked";i:424;s:17:"Failed Dependency";i:425;s:20:"Unordered Collection";i:426;s:16:"Upgrade Required";i:428;s:21:"Precondition Required";i:429;s:17:"Too Many Requests";i:431;s:31:"Request Header Fields Too Large";i:500;s:21:"Internal Server Error";i:501;s:15:"Not Implemented";i:502;s:11:"Bad Gateway";i:503;s:19:"Service Unavailable";i:504;s:16:"Gateway Time-out";i:505;s:26:"HTTP Version not supported";i:506;s:23:"Variant Also Negotiates";i:507;s:20:"Insufficient Storage";i:508;s:13:"Loop Detected";i:511;s:31:"Network Authentication Required";}s:13:"*statusCode";i:200;s:15:"*reasonPhrase";N;s:10:"*headers";O:17:"Zend\Http\Headers":3:{s:20:"*pluginClassLoader";N;s:14:"*headersKeys";a:1:{i:0;s:13:"xstrokercache";}s:10:"*headers";a:1:{i:0;a:2:{s:4:"name";s:15:"X-Stroker-Cache";s:4:"line";s:21:"X-Stroker-Cache: Miss";}}}s:11:"*metadata";a:0:{}s:10:"*content";s:17142:"
Try setting cache_response to false
. Setting this to true
(which is the default value) will cause the whole response (including headers) to be cached which is not feasible for the File cache.
'strokercache' => [
'cache_response' => false
]
Hope this helps.
@bramstroker ok this way works! So we need a specific versione of id_generator that work with File storage adapter. To resolve the problem of cache invalidation the only solution is like @matiasfuster said, it depends on domain specific rules ...