55use app \middleware \HeaderSecurityMiddleware ;
66use DOMDocument ;
77use DOMXPath ;
8+ use flight \core \EventDispatcher ;
89use flight \Engine ;
910
1011class DocsLogic {
@@ -60,11 +61,18 @@ public function compileSinglePage(string $language, string $version, string $sec
6061
6162 $ Translator = $ this ->setupTranslatorService ($ language , $ version );
6263
63- $ markdown_html = $ app ->cache ()->refreshIfExpired ($ section . '_html_ ' . $ language . '_ ' . $ version , function () use ($ app , $ section , $ Translator ) {
64+ $ cacheStartTime = microtime (true );
65+ $ cacheHit = true ;
66+ $ cacheKey = $ section . '_html_ ' . $ language . '_ ' . $ version ;
67+ $ markdown_html = $ app ->cache ()->retrieve ($ cacheKey );
68+ if ($ markdown_html === null ) {
69+ $ cacheHit = false ;
6470 $ markdown_html = $ app ->parsedown ()->text ($ Translator ->getMarkdownLanguageFile ($ section . '.md ' ));
6571 $ markdown_html = Text::addClassesToElements ($ markdown_html );
66- return $ markdown_html ;
67- }, 86400 ); // 1 day
72+ $ app ->cache ()->store ($ cacheKey , $ markdown_html , 86400 ); // 1 day
73+ }
74+
75+ $ app ->eventDispatcher ()->trigger ('flight.cache.checked ' , 'compile_single_page_ ' .$ cacheKey , $ cacheHit , microtime (true ) - $ cacheStartTime );
6876
6977 $ markdown_html = $ this ->wrapContentInDiv ($ markdown_html );
7078
@@ -88,19 +96,26 @@ public function compileScrollspyPage(string $language, string $version, string $
8896
8997 $ Translator = $ this ->setupTranslatorService ($ language , $ version );
9098
91- $ section_file_path = str_replace ('_ ' , '- ' , $ section );
99+ $ section_file_path = str_replace ('_ ' , '- ' , $ section );
92100 $ sub_section_underscored = str_replace ('- ' , '_ ' , $ sub_section );
93101 $ heading_data = $ app ->cache ()->retrieve ($ sub_section_underscored . '_heading_data_ ' . $ language . '_ ' . $ version );
94- $ markdown_html = $ app ->cache ()->refreshIfExpired ($ sub_section_underscored . '_html_ ' . $ language . '_ ' . $ version , function () use ($ app , $ section_file_path , $ sub_section , $ sub_section_underscored , &$ heading_data , $ language , $ Translator , $ version ) {
95- $ parsed_text = $ app ->parsedown ()->text ($ Translator ->getMarkdownLanguageFile ('/ ' . $ section_file_path . '/ ' . $ sub_section_underscored . '.md ' ));
102+
103+ $ cacheStartTime = microtime (true );
104+ $ cacheHit = true ;
105+ $ cacheKey = $ sub_section_underscored . '_html_ ' . $ language . '_ ' . $ version ;
106+ $ markdown_html = $ app ->cache ()->retrieve ($ cacheKey );
107+ if ($ markdown_html === null ) {
108+ $ cacheHit = false ;
109+ $ markdown_html = $ app ->parsedown ()->text ($ Translator ->getMarkdownLanguageFile ('/ ' . $ section_file_path . '/ ' . $ sub_section_underscored . '.md ' ));
96110
97111 $ heading_data = [];
98- $ parsed_text = Text::generateAndConvertHeaderListFromHtml ($ parsed_text , $ heading_data , 'h2 ' , $ section_file_path .'/ ' .$ sub_section );
99- $ parsed_text = Text::addClassesToElements ($ parsed_text );
112+ $ markdown_html = Text::generateAndConvertHeaderListFromHtml ($ markdown_html , $ heading_data , 'h2 ' , $ section_file_path .'/ ' .$ sub_section );
113+ $ markdown_html = Text::addClassesToElements ($ markdown_html );
100114 $ app ->cache ()->store ($ sub_section_underscored . '_heading_data_ ' . $ language . '_ ' . $ version , $ heading_data , 86400 ); // 1 day
115+ $ app ->cache ()->store ($ cacheKey , $ markdown_html , 86400 ); // 1 day
116+ }
101117
102- return $ parsed_text ;
103- }, 86400 ); // 1 day
118+ $ app ->eventDispatcher ()->trigger ('flight.cache.checked ' , 'compile_scrollspy_page_ ' .$ cacheKey , $ cacheHit , microtime (true ) - $ cacheStartTime );
104119
105120 // pull the title out of the first h1 tag
106121 $ page_title = '' ;
0 commit comments