14

I'm working on a Laravel 5.1 project, using a lot of ajax calls returning html blocks.

To optimize the speed of the website i want to implement private and public response caching. this works fine using following code:

        return response()
        ->json($result)
        ->header('Cache-Control', 'public, max-age=300');

Yet using it this way wont hold in account objects that are updated within the 300 seconds.

Are there possibilities that allow me to clear the response cache of a request, if and only if the returning objects have been updated ?

4

2 に答える 2

0

以下のようなものでサーバー側のキャッシュを試すことができるかもしれません。すみません、これは粗雑です

function sometest(User $user)
{

    /** . . .conditions to check if some data has changed . . . **/


    $jsonResponse = Cache::remember(Auth::id() . "_sometest", 300, function () use ($user)
    {
        $result = $user->all(); //get result here

        return $result;
    });

    return response()->json($jsonResponse);
}

ここでキャッシュについて読むことができます

あなたも試すことができます

于 2016-04-21T15:35:00.227 に答える