Confidence Posted March 1, 2010 Share Posted March 1, 2010 hi guys, i have the following function //getting all providers function getAllProviders($tarifarray) { $i = 0; $provider_array = array (); foreach ( $tarifarray ['tarifarray'] as $key => $val ) { $energyprovider = $val ['versorgerName']; $providerid = $i; $temparray = array ($energyprovider => $providerid ); $provider_array = array_merge ( ( array ) $provider_array, ( array ) $temparray ); $i ++; } return $provider_array; } and it is recalled in many cases with the same result....how can i configure it so it caches the return value? unless it changes. Quote Link to comment https://forums.phpfreaks.com/topic/193756-caching-a-functions-array-result/ Share on other sites More sharing options...
ram4nd Posted March 1, 2010 Share Posted March 1, 2010 you can store the result on global variable or something. You can't actually do what you want, cause in that case you need to check in the result is the same, witch is basically the same code. So you just have to store the result somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/193756-caching-a-functions-array-result/#findComment-1019800 Share on other sites More sharing options...
jl5501 Posted March 1, 2010 Share Posted March 1, 2010 If the many calls you describe, are all on the same page, then you can set this up as a class, have the array as a class variable, then when instantiating you set up the array, then you would have a function to get the array when necessary. The global storage is also an option as has been suggested. If the resultant array is required on many pages, then storing it in the session would be an answer for you Quote Link to comment https://forums.phpfreaks.com/topic/193756-caching-a-functions-array-result/#findComment-1019802 Share on other sites More sharing options...
Confidence Posted March 1, 2010 Author Share Posted March 1, 2010 thanks guys. you can store the result on global variable or something. You can't actually do what you want, cause in that case you need to check in the result is the same well if i have to check if it is same each time, then i am doing the calculation again which consumes resources...or not? Quote Link to comment https://forums.phpfreaks.com/topic/193756-caching-a-functions-array-result/#findComment-1019803 Share on other sites More sharing options...
Goat Posted March 1, 2010 Share Posted March 1, 2010 thanks guys. you can store the result on global variable or something. You can't actually do what you want, cause in that case you need to check in the result is the same well if i have to check if it is same each time, then i am doing the calculation again which consumes resources...or not? Yeah. Unless you put trigger or something on function that changes values, so it has to calculate only when someone changes values. I am not sure if that is possible in you case thought. Goat Quote Link to comment https://forums.phpfreaks.com/topic/193756-caching-a-functions-array-result/#findComment-1019847 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.