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

caching docs is confusing and missing important info #54

Open
vesper8 opened this issue Nov 20, 2017 · 3 comments
Open

caching docs is confusing and missing important info #54

vesper8 opened this issue Nov 20, 2017 · 3 comments

Comments

@vesper8
Copy link

vesper8 commented Nov 20, 2017

Took me a while to figure out how the cache works and had to read a lot of issues and look into the code to finally get to the conclusion that on top of enabling the cache in the config file, you must add this code at the top of your controller action to return the cached version

        if (Sitemap::hasCachedView()) {
            return Sitemap::render();
        }
@dwightwatson
Copy link
Owner

You shouldn't have to do that - the render() method will check for a cached view and return it by default. See these lines.

@vesper8
Copy link
Author

vesper8 commented Nov 20, 2017

@dwightwatson I know the render() does that.. I noticed

However I don't understand the thinking behind this since the call to Sitemap::render() is usually done after doing all the processing.

My controller action for one of my sitemaps (a big one with 5k url and 10k images, does a huge amount of processing in order to build up the sitemap. How is having a check for a cached version at the bottom of that code allowing to skip the processing.. which is the point of caching.

Maybe there's something I'm not getting?

Here's my code


    public function submission(Game $game)
    {
        if (Sitemap::hasCachedView()) {
            return Sitemap::render();
        }

        ini_set("max_execution_time", 240);
        ini_set("memory_limit", "1024M");

        $imageHelpers = new ImageHelpers();

        $input = [
            "game_id" => $game->id,
        ];
        $submissions = Submission::getSubmissions("sitemap", $input);

        foreach ($submissions as $submission) {
            $tag = Sitemap::addTag($submission->url(), $submission->updated_at, "daily", "0.8");

            $title = $submission->getTitleForSeo() . " in " . $submission->game->name;

            foreach ($submission->getMedia("submissions") as $image) {
                $tag->addImage(url($imageHelpers->getGlideUrl($image, "watermarked")), $title);
            }
        }

        return Sitemap::render();
    }

@dwightwatson
Copy link
Owner

Yeah... that's actually a very fair point.

Will re-open this as to address the documentation on this area better. Open to PRs on it otherwise I'll try and find some time to improve this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants