vendredi 29 avril 2016

How do I cache the current authenticated user? (Laravel 5)

Description

In my situation, I don't have a users table locally, but I have an api that will provide me a list of users.


getUsers()

I modify my getUsers() for my Auth::user() in app/Auth/ApiUserProvider.php

protected function getUsers()
{
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, env('API_HOST') . 'vse/accounts');

    $response = curl_exec($ch);
    $response = json_decode($response, true);

    curl_close($ch);

    return $response['data'];
}


Issue

Each time, I used Auth::user() in my code. It makes a call to my API .../vse/accounts It effects a lot of latency in my application.


How do I solve this ?

Should I start using cache ? If so, how do I modify what I have to do something like that ?

Should I store it in the session ?

I'm open to any suggestions right now.

Any hints / suggestions on this will be much appreciated !



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1roDtPq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire