• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

laravel的cache get是怎么进行调用的?(代码示例)

php 搞代码 3年前 (2022-01-21) 14次浏览 已收录 0个评论

本篇文章给大家带来的内容是关于laravel的cache get是怎么进行调用的?(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

本文使用版本为laravel5.5

cache get

public function cache()    {        $c=\Cache::get('app');        if(!$c) {            \Cache::put('app', 'cache', 1);        }        dump($c);//cache    }

config/app.php

 'aliases' => [        'App' => Illuminate\Support\Facades\App::class,        'Artisan' => Illuminate\Support\Facades\Artisan::class,        'Auth' => Illuminate\Support\Facades\Auth::class,        'Blade' => Illuminate\Support\Facades\Blade::class,        'Broadcast' => Illuminate\Support\Facades\Broadcast::class,        'Bus' => Illuminate\Support\Facades\Bus::class,        'Cache' => Illuminate\Support\Facades\Cache::class,                ]

使用cache实际调用的是Illuminate\Support\Facades\Cache,这个映1本文来#源gaodai$ma#com搞$代*码*网

搞代gaodaima码

射是如何做的?

public/index.php

$response = $kernel->handle($request = Illuminate\Http\Request::capture());

bootstarp/app.php

$app->singleton(    Illuminate\Contracts\Http\Kernel::class,    App\Http\Kernel::class);

app/http/kernel.php

use Illuminate\Foundation\Http\Kernel as HttpKernel;class Kernel extends HttpKernel{}

Illuminate/Foundation/Http/Kernel.php

public function handle($request){    try {        $request->enableHttpMethodParameterOverride();        $response = $this->sendRequestThroughRouter($request);    } catch (Exception $e) {        $this->reportException($e);        $response = $this->renderException($request, $e);    } catch (Throwable $e) {        $this->reportException($e = new FatalThrowableError($e));        $response = $this->renderException($request, $e);    }    $this->app['events']->dispatch(        new Events\RequestHandled($request, $response)    );    return $response;}protected function sendRequestThroughRouter($request)    {        $this->app->instance('request', $request);        Facade::clearResolvedInstance('request');        $this->bootstrap();        return (new Pipeline($this->app))                    ->send($request)                    ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)                    ->then($this->dispatchToRouter());    }    public function bootstrap()    {        if (! $this->app->hasBeenBootstrapped()) {            $this->app->bootstrapWith($this->bootstrappers());        }    }

Illuminate/Foundation/Application.php

public function bootstrapWith(array $bootstrappers)    {        $this->hasBeenBootstrapped = true;        foreach ($bootstrappers as $bootstrapper) {            $this['events']->fire('bootstrapping: '.$bootstrapper, [$this]);            $this->make($bootstrapper)->bootstrap($this);            $this['events']->fire('bootstrapped: '.$bootstrapper, [$this]);        }    }

Illuminate/Foundation/Bootstrap/RegisterFacades.php

public function bootstrap(Application $app)    {        Facade::clearResolvedInstances();        Facade::setFacadeApplication($app);//将config/app.php 里的aliases数组里面的Facades类设置别名        AliasLoader::getInstance(array_merge(            $app->make('config')->get('app.aliases', []),            $app->make(PackageManifest::class)->aliases()        ))->register();    }

Illuminate/Foundation/AliasLoader.php

public function load($alias)    {        if (static::$facadeNamespace && strpos($alias, static::$facadeNamespace) === 0) {            $this->loadFacade($alias);            return true;        }      // $alias来自于config/app.php中aliases数组         if (isset($this->aliases[$alias])) {            //'Route' => Illuminate\Support\Facades\Route::class,            // class_alias 为一个类创建别名            return class_alias($this->aliases[$alias], $alias);        }    }

Illuminate/Support/Facades/Cache.php

class Cache extends Facade{    /**     * Get the registered name of the component.     *     * @return string     */    protected static function getFacadeAccessor()    {        return 'cache';    }}

Illuminate/Support/Facades/Facade.php


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:laravel的cache get是怎么进行调用的?(代码示例)
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址