Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Server \ Laravel cache paged results     - Spring Integration ehcache annotation implement the query cache and cache update or delete instant (Programming)

- MyCAT easy entry (Database)

- Ubuntu 14.04 users how to install VLC 2.2.0 (Linux)

- Java JDK has been able to compile without warning (Programming)

- VMware Workstation virtual machine Ubuntu achieve shared with the host (Linux)

- The callback function used in C ++ (Programming)

- MySQL management partition table (Database)

- About Leetcode on Binary Tree Algorithm summary (Programming)

- Set multiple IP addresses for a single network card on Ubuntu 15.10 (Linux)

- Oracle inverted reverse function (Database)

- IBM Data Studio to use ---- window displays all rows (Database)

- CV: Linux command displays the progress of the run command (Linux)

- HDFS Distributed File System Resource Manager Developer summary (Server)

- Oracle background processes daemons (Database)

- Setting Linux desktop environment, achieve HiDPI display support (Linux)

- Linux System Getting Started Tutorial: How to find the maximum memory your system supports (Linux)

- Oracle Database ORA-01555 snapshot too old (Database)

- Linux iptables firewall settings whitelist (RHEL 6 and CentOS 7) (Linux)

- How to use the command line to obtain Freely RSS source on Linux (Linux)

- The Linux-based security settings Ipchains Firewall (Linux)

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

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).
- HttpClient Tutorial (Programming)
- High-performance JavaScript DOM programming (Programming)
- Intruder tools Knark Analysis and Prevention Linux environment (Linux)
- MySQL 5.6 Open full query log (Database)
- Git uses a small mind (Linux)
- How Glances monitoring system on Ubuntu (Linux)
- CentOS 6.4 install and configure Squid Proxy Server (Linux)
- On FreeBSD 10.2 Bugzilla how to install and configure Apache SSL (Server)
- ActiveMQ5.11.1 and JDK version matching relation (Linux)
- PostgreSQL Select source code analysis (Database)
- Linux, security encryption to transfer files between machines (Linux)
- Iptables in Ubuntu (Linux)
- Linux script to copy the folder to all folders with the same name (Linux)
- Hanoi problem Java Solution (Programming)
- swap space is insufficient cause OOM kill MySQL Case (Database)
- Shell Script: Bulk add users, and set the random character password (Programming)
- Binding unofficial Google Drive and Ubuntu 14.04 LTS (Linux)
- Graphing tool: Gnuplot (Linux)
- Python when automated operation and maintenance often used method (Programming)
- Use Linux firewall camouflage defense hacked (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.