dolejska-daniel / riot-api

Riot League of Legends & DataDragon API wrappers for PHP7 and PHP8.
GNU General Public License v3.0
112 stars 25 forks source link

Custom Cache Provider bug #35

Closed regiszanandrea closed 5 years ago

regiszanandrea commented 5 years ago

Describe the bug I'm getting this error on a implementation of a custom cache provider: 'RiotAPI\LeagueAPI\LeagueAPI::RiotAPI\LeagueAPI{closure}(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "RiotAPI\Definitions\RateLimitControl" of the object you are trying to operate on was loaded before unserialize() gets called or provide an autoloader to load the class definition'

To Reproduce Steps to reproduce the behavior:

Main code

use RiotAPI\LeagueAPI\Definitions\Region;
use RiotAPI\LeagueAPI\LeagueAPI;

$riot = new LeagueAPI([
                LeagueAPI::SET_KEY => config('riot.key'),
                LeagueAPI::SET_TOURNAMENT_KEY => config('riot.key'),
                LeagueAPI::SET_REGION => Region::BRASIL,
                LeagueAPI::SET_CACHE_RATELIMIT => config('riot.rate_limit_control_enabled'),
                LeagueAPI::SET_CACHE_PROVIDER => RiotRedisProvider::class,
                LeagueAPI::SET_CACHE_CALLS => config('riot.cache_enabled')
            ]);
return $riot->getSummonerByName('Just Sieg');

RiotRedisProvider

use Illuminate\Support\Facades\Cache;
use RiotAPI\LeagueAPI\Definitions\ICacheProvider;

class RiotRedisProvider implements ICacheProvider
{

    /**
     *   Loads data stored in cache memory.
     *
     * @param string $name
     * @return mixed
     */
    public function load(string $name)
    {
        return Cache::get($name);
    }

    /**
     *   Saves data to cache memory.
     *
     * @param string $name
     * @param        $data
     * @param int $length
     *
     * @return bool
     */
    public function save(string $name, $data, int $length): bool
    {
        Cache::put($name, $data, $length);
        return true;
    }

    /**
     *   Checks whether or not is saved in cache.
     *
     * @param string $name
     *
     * @return bool
     */
    public function isSaved(string $name): bool
    {
        return Cache::has($name);
    }
}

Expected behavior Execute correctly the request

Screenshots https://drive.google.com/file/d/1IYMXGJsbeNfx7CJB7ScVbIiYtn-C-h2k/view?usp=sharing

Server (please complete the following information):

Additional context I'm using Laravel.

dolejska-daniel commented 5 years ago

Hi, this looks like you've got some old values stuck in cache to me. Try cleaning your cache provider and tell me whether it helps.

regiszanandrea commented 5 years ago

You're right 👍 thanks @dolejska-daniel