1717use SilverStripe \View \ArrayData ;
1818use Psr \SimpleCache \CacheInterface ;
1919use SilverStripe \Core \Injector \Injector ;
20+ use SilverStripe \Core \Environment ;
2021
2122/**
2223 * Pardot Controller
@@ -29,7 +30,7 @@ class PardotController extends Controller
2930{
3031 protected static $ FORMS_CACHE_KEY = 'pardot_cache_forms ' ;
3132 protected static $ DYNAMIC_CONTENTS_CACHE_KEY = 'pardot_dynamic_contents ' ;
32- protected static $ CACHE_DURATION = ( 60 * 60 ) * 6 ; //6 hours
33+ protected static $ CACHE_DURATION = ( 60 * 60 ) * 2 ; //2 hours
3334
3435 private static $ url_segment = 'pardot ' ;
3536
@@ -127,15 +128,16 @@ private function getForms()
127128 return unserialize ($ cache ->get (self ::$ FORMS_CACHE_KEY ));
128129 }
129130
130- foreach (PardotApiService::getApi ()->form ()->query ()->form as $ form ) {
131+ $ queryForm = PardotApiService::getApi ()->form ()->query ()->form ;
132+ foreach ($ queryForm as $ form ) {
131133 $ forms ->push (ArrayData::create ([
132134 'ID ' => $ form ->id ,
133135 'Title ' => sprintf ('%s - %s ' , $ form ->campaign ->name , $ form ->name ),
134136 'EmbedCode ' => $ form ->embedCode ,
135137 ]));
136138 }
137139 $ formList = $ forms ->Sort ('Title ' )->map ();
138- $ cache ->set (self ::$ FORMS_CACHE_KEY , serialize ($ formList ), self :: $ CACHE_DURATION );
140+ $ cache ->set (self ::$ FORMS_CACHE_KEY , serialize ($ formList ), static :: getCacheDuration () );
139141
140142 return $ formList ;
141143 }
@@ -159,8 +161,15 @@ private function getDynamicContent()
159161 ]));
160162 }
161163 $ contentList = $ contents ->Sort ('Title ' )->map ();
162- $ cache ->set (self ::$ DYNAMIC_CONTENTS_CACHE_KEY , serialize ($ formList ), self :: $ CACHE_DURATION );
164+ $ cache ->set (self ::$ DYNAMIC_CONTENTS_CACHE_KEY , serialize ($ formList ), static :: getCacheDuration () );
163165
164166 return $ contentList ;
165167 }
168+
169+ protected static function getCacheDuration ()
170+ {
171+ $ duration = Environment::getEnv ('PARDOT_CACHE_DURATION ' );
172+
173+ return ((int )$ duration > 0 ) ? (int )$ duration : static ::$ CACHE_DURATION ;
174+ }
166175}
0 commit comments