-
Notifications
You must be signed in to change notification settings - Fork 27
OriginalRouteExtractor Serialization of 'Closure' is not allowed #332
Comments
Hi @gomcodoctor |
@ElectricMaxxx thanks for replying Serialization of 'Closure' is not allowed, PHP version 7.1.9 in vendor/symfony-cmf/seo-bundle/src/Cache/ExtractorCollection.php (line 88) in vendor/symfony-cmf/seo-bundle/src/Cache/ExtractorCollection.php (line 88) in vendor/symfony-cmf/seo-bundle/src/Cache/FileCache.php (line 71) in vendor/symfony-cmf/seo-bundle/src/SeoPresentation.php (line 173) in vendor/symfony-cmf/seo-bundle/src/SeoPresentation.php (line 213) |
I have debugged it, issue occur when we serialize "$urlGenerator" ( which is router service ) in OriginalRouteExtractor, because router service has Closure {#364 ▼ class: "appDevDebugProjectContainer |
Maybe @wouterj can give some hints as he created the cache. My first idea is to implement |
@ElectricMaxxx ya i think |
In generall i would ask @wouterj why decided to cache an object that generates something instead of caching the result it had? |
as per my understanding - he is trying to cache all extractors OBJECT applicable to given object or resource, extractor which has dependency on other service is prone to this issue, instead of caching whole extractor object, caching name of extractor is enough i think, Please correct me if I am wrong, I am not that symfony expert |
Yeah, indeed, caching the name is probably enough. We then have to rework SeoPresentation a bit (if the extractor class names are cached, we have to filter all instances based on the cache name before using them), but it's probably the best solution. @ElectricMaxxx caching values would mean we have to clear the cache each time the value changes. And that value most of the time is a getter, so it can depend on anything out there in the world. Caching here is used to already know which extractors apply to the object, which speed up things a bit already. |
@wouterj thanks for reply.
|
@wouterj but where is the advantage to store a class name and instantiate and call it then, when it normally commes as service defintion from DI, which should be cached at all? |
@ElectricMaxxx you are right, I think we do not need cache when number of extractors are very small, cache will be useful when there are hundreds of extractors |
When trying to use OriginalRouteExtractor
there is exception " Serialization of 'Closure' is not allowed " because of router service having a closure
public function serialize() { return serialize([ $this->extractors, $this->resource, $this->createdAt, ]); }
-configCacheFactory: ResourceCheckerConfigCacheFactory {#365 ▼ -resourceCheckers: RewindableGenerator {#363 ▼ -generator: Closure {#364 ▼ class: "appDevDebugProjectContainer" this: appDevDebugProjectContainer {#519 …14} file: "/var/cache/dev/appDevDebugProjectContainer.php" line: "2038 to 2041" } -count: 2 }
The text was updated successfully, but these errors were encountered: