Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ViewCells] caching #7663

Merged
merged 2 commits into from
Jul 6, 2023
Merged

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jul 6, 2023

Description
Passing parameters as string and array makes two cache files.

Before:

+---------------------------------------------------------+---------------------------------------------------------------------------------+-----------+---------------------+
| Name                                                    | Server Path                                                                     | Size      | Date                |
+---------------------------------------------------------+---------------------------------------------------------------------------------+-----------+---------------------+
| AppCellsMyClassCellshow8fd4938d6f28a83da659a38e14e300b0 | ROOTPATH/writable/cache/AppCellsMyClassCellshow8fd4938d6f28a83da659a38e14e300b0 | 78 Bytes  | 2023-07-06 07:12:17 |
| index.html                                              | ROOTPATH/writable/cache/index.html                                              | 131 Bytes | 2023-03-18 04:20:06 |
| AppCellsMyClassCellshow8b13b3e90d21dd18ff835058c0c1d093 | ROOTPATH/writable/cache/AppCellsMyClassCellshow8b13b3e90d21dd18ff835058c0c1d093 | 78 Bytes  | 2023-07-06 07:12:17 |
+---------------------------------------------------------+---------------------------------------------------------------------------------+-----------+---------------------+

After:

+---------------------------------------------------------+---------------------------------------------------------------------------------+-----------+---------------------+
| Name                                                    | Server Path                                                                     | Size      | Date                |
+---------------------------------------------------------+---------------------------------------------------------------------------------+-----------+---------------------+
| AppCellsMyClassCellshow8fd4938d6f28a83da659a38e14e300b0 | ROOTPATH/writable/cache/AppCellsMyClassCellshow8fd4938d6f28a83da659a38e14e300b0 | 78 Bytes  | 2023-07-06 07:12:52 |
| index.html                                              | ROOTPATH/writable/cache/index.html                                              | 131 Bytes | 2023-03-18 04:20:06 |
+---------------------------------------------------------+---------------------------------------------------------------------------------+-----------+---------------------+
<?php

namespace App\Cells;

class MyClassCell
{
    public function show(array $params): string
    {
        return $params['param1'] . $params['param2'];
    }
}
<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        return view_cell('MyClassCell::show', ['param1' => 'value1', 'param2' => 'value2'], 3600)
            . view_cell('MyClassCell::show', 'param1=value1, param2=value2', 3600);
    }
}

Checklist:

  • Securely signed commits
  • [] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [] Unit testing, with >80% coverage
  • [] User guide updated
  • Conforms to style guide

@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 6, 2023
@MGatner
Copy link
Member

MGatner commented Jul 6, 2023

Not sure if you care but "normalize" got terribly typoed in your commit message 😅

If you call view_cell() with param ['param1' => 'value1'], and call
with param 'param1=value1', they should be one cache.
@kenjis
Copy link
Member Author

kenjis commented Jul 6, 2023

That's terrible!
Fixed. Thanks.

@kenjis kenjis merged commit 1a83ef4 into codeigniter4:develop Jul 6, 2023
50 checks passed
@kenjis kenjis deleted the fix-view-cell-caching branch July 6, 2023 23:37
@MGatner
Copy link
Member

MGatner commented Jul 8, 2023

Almost got it! 😇 No big deal, not worth messing with develop

- fix: normailze params 
+ fix: normalize params 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants