Home » Php » What is the best method to use cache when we have to retrieve data for date range

What is the best method to use cache when we have to retrieve data for date range

Posted by: admin October 26, 2017 Leave a comment

Questions:

I have to prepare set of large reports which handle number of table joins and grouping conditions. So loading of this report is pretty slow. Current method of doing this is retrieving retrieving total set of data without joins or grouping and do those functions using code(calculations and arrays)

ex:

for ($i = 1; $i <= $days_in_month; $i++):
    $date = "$year_info-$month_info-$i";
    $date1 = date("Y-m-d", strtotime($date));
    if ($weighted_date == $date1):
        $field_kg[$field_id][$date1] = $cash_kilo + $field_cash_kg[$field_id][$date1];
        if ($plantation_id == 2) {
            $cas_nor_kg[$field_id][$date1] = $field_cash_kg[$field_id][$date1] + $field_kg[$field_id][$date1];
        } else {
            $cas_nor_kg[$field_id][$date1] = $field_kg[$field_id][$date1];
        }
        $cas_nor_kg[$field_id][$date1] = $field_cash_kg[$field_id][$date1];
        $field_round[$field_id][$date1] = $round_number;
    endif;
endfor;

So as you can see this makes code hard to read. So is there a method to use cache in these kind of scenarios and how?

Answers: