Giter Site home page Giter Site logo

在项目里使用laravel服务提供者+门面,方法里面查询的数据常住内存,每次进来都使用同一数据源 about laravel-tars HOT 3 CLOSED

luoxiaojun1992 avatar luoxiaojun1992 commented on May 11, 2024
在项目里使用laravel服务提供者+门面,方法里面查询的数据常住内存,每次进来都使用同一数据源

from laravel-tars.

Comments (3)

luoxiaojun1992 avatar luoxiaojun1992 commented on May 11, 2024

看不太明白,请提供示例代码和说明

from laravel-tars.

wx1860 avatar wx1860 commented on May 11, 2024

class PayServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->singleton('pay', function ($app) {
$config = $app->make('config')->get('pay');
return new PayManager($config);
});
}
}
在PayManager这个类的__construct方法中写了数据库查询数据,每次请求进来都查到的是同一数据,修改数据库必须重启tars服务才生效

from laravel-tars.

luoxiaojun1992 avatar luoxiaojun1992 commented on May 11, 2024

Provider 的 register 应该只会执行一次,而且 Provider 在请求所有接口的时候应该都会执行,包括执行脚本。是否可以尝试用 middleware 实现。

from laravel-tars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.