Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refreshPath has no effect with Symfony3.2 & FOSRestBundle #362

Closed
@websirnik

Description

@websirnik

I'm using Symfony HttpCache. In my case when I call $this->get('fos_http_cache.cache_manager')->refreshPath('/api/post/xyz') or invalidatePath()my cache does not get refreshed / cleared.

I can see that $this->get('fos_http_cache.cache_manager')->flush() does execute the correct GET request, but the cache still serves the old response.

I'm not sure about the root cause. Please help me debug this. Here is my configs that might be relevant.

Active packages:

"require": {        
    "friendsofsymfony/http-cache-bundle": "^2.0.0-alpha1",
    "friendsofsymfony/http-cache": "^2.0.0-beta1",     
    "friendsofsymfony/rest-bundle": "~2.1.0",  
    "guzzlehttp/guzzle": "~6.0",
    "guzzlehttp/psr7": "^1.4",
    "symfony/symfony": "~3.2.0"
}

config.yml:

fos_http_cache:
    invalidation:
        enabled: true
    proxy_client:
        symfony:
            http:
                servers:
                    - example.dev
                base_url: example.dev

AppCache.php:

<?php

require_once __DIR__ . '/AppKernel.php';

use FOS\HttpCache\SymfonyCache\CacheInvalidation;
use FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache;
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
use Symfony\Component\HttpFoundation\Request;

class AppCache extends HttpCache implements CacheInvalidation {
	use EventDispatchingHttpCache;

	/**
	 * Made public to allow event listeners to do refresh operations.
	 *
	 * {@inheritDoc}
	 */
	public function fetch(Request $request, $catch = false) {
		return parent::fetch($request, $catch);
	}
}

Controller action that sets cache properties:

/**
 * [GET] /api/post/{slug}
 */
public function getPostAction($slug) {

	// ...
	// Getting $post  { .. }
	// ...

	$response = new Response();

	$response->setPublic();
	$response->setSharedMaxAge(86400);

	$view = $this->view($post);
	$view->setResponse($response);

	return $this->handleView($view);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions