Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ Laravel cache paged results     - Extended use of the swap file swap space on Linux (Linux)

- Remove old kernel on Ubuntu (Linux)

- Linux LVM - File system extension (Linux)

- Protect your files, modify the Linux value Umask (Linux)

- Linux find command detailing (Linux)

- Binder began to talk about inter-process communication mechanism from Android AIDL (Programming)

- Some of the bibliographic management tools to good use on linux (Linux)

- Minimum period string problem (Programming)

- After CentOS configure SSH password Free, still prompted for a password (Linux)

- Linux crontab commands and detailed usage examples (Linux)

- Do you know how to build the Linux kernel (Programming)

- Installation of Theano + CUDA under Ubuntu (Linux)

- Android using shape drawable material production (Programming)

- Graphical development environment to build Android under Ubuntu 11.04 (Linux)

- Boost notes --Thread - problems encountered in the initial use on Ubuntu (Programming)

- RAID disk array Description (Linux)

- Solaris 10 nagios monitoring system (Linux)

- Install Gnome Flashback Classic Desktop on Ubuntu 14.10 / Mint 7 (Linux)

- Python-- for anomalies and reflection of objects articles (Programming)

- Learning MySQL data types (Database)

 
         
  Laravel cache paged results
     
  Add Date : 2018-11-21      
         
         
         
  Foreword

Improve page speed of a good use of the method is to use Cache. Use and configure Laravel in Cache is quite convenient, reasonable use in the project can get unexpected results (of course, improper use can also cause bad effect).

Problems encountered

So, I wrote the following seemingly very normal code:

$ NewsList = Cache :: remember ( 'newsList'. $ Uuid, $ minutes, function () {
    return News :: with ( 'lastReplyUser', 'user')
        -> Checked ()
        -> RecentReply ()
        -> Paginate (Config :: get ( 'page.newsListSize'));
});
Results let me refresh the page after the unexpected, given Exception Serialization of 'Closure' is not allowed.

Analyse problem

Susu open xdebug debugging, obviously returns Paginator this object. How you will say it can not be serialized Closure?

As the error message, the paginator object has properties are closures, they can not be in the sequence of the time.

In strong xdebug's help, I found the culprit.

Behavior /Path/To/Nidexiangmu/vendor/laravel/framework/src/Illuminate/View/Engines/EngineResolver.php 30 lines of this method: the specific location of the assignment

public function register ($ engine, Closure $ resolver)
    {
        $ This-> resolvers [$ engine] = $ resolver;
    }
Solve the problem

Casually modify the source code framework, which we are not capable of thing. If so, then come to a Quxianjiuguo it! Unable to paginator cache, it can cache something else.

plan 1

Query cache

$ NewsList = News :: with ( 'lastReplyUser', 'user')
    -> Checked ()
    -> WhereNotIn ( 'id', $ selectedId)
    -> RecentReply ()
    -> Remember ($ minutes) # Note that this line
    -> Paginate (Config :: get ( 'page.newsListSize'));
Scenario 2

Paginator for the need to use the content (items and links) cache

$ NewsList = Cache :: remember ( 'newsList'. $ Uuid, $ minutes, function () {
    $ Data = News :: with ( 'lastReplyUser', 'user')
        -> Checked ()
        -> RecentReply ()
        -> Paginate (Config :: get ( 'page.newsListSize'));

    return [ 'result' => $ data-> getItems (), 'links' => (string) $ data-> links ()];
});
to sum up

Note that, in Scenario 2 * links () * When this method is called using the cast string, because the returned content is view objects, properties view object has closures, so any time do not try to serialize (including cache the operation of such operations contains the serial number) view objects and view object properties have an array or object (this sentence is good mouthful ah, in fact, exists only view objects do not serialize or cache).
     
         
         
         
  More:      
 
- Ubuntu Tutorial - Manually install Oracle Java JDK 8 (Linux)
- How to upgrade Docker 1.6 on Fedora / CentOS (Server)
- Android code performance optimization tips (Programming)
- TL-WR703N to install OpenWrt process notes (Linux)
- Disk Management LVM (Linux)
- Bubble Sort Algorithms (Programming)
- Iptables principle (Linux)
- Laravel 4.2 Laravel5 comprehensive upgrade Raiders (Server)
- Sysdig: system troubleshooting tool (Linux)
- LNMP summary of the issues common 502 Bad Gateway (Server)
- Build Golang development environment configuration on Ubuntu 14.04 (Linux)
- Windows SmartGit installation (Linux)
- jQuery get value drop-down list and select text (Programming)
- Ubuntu: HDF5 error: HDF5 header version does not match with the HDF5 library (Linux)
- Interesting example of Linux Sort command (Linux)
- Two alert log ORA Errors (Database)
- Linux data recovery software efficiently practical application extundelete (Linux)
- Linux how to prohibit the use of Ping command (Linux)
- Android project and coding specifications (Programming)
- Oriented C ++ test-driven development (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.