1313class Cache
1414{
1515 /**
16- * @var array<string, array<string, Resource>> $cache
16+ * @var array<string, array<string, Resource|string >> $cache
1717 */
1818 protected array $ cache = [];
1919
@@ -39,15 +39,18 @@ public function add(Resource $resource): void
3939 $ resource ->setInternalId (uniqid ());
4040 }
4141
42+ if ($ resource ->getName () == Resource::TYPE_DOCUMENT ) {
43+ $ status = $ resource ->getStatus ();
44+ $ documentId = $ resource ->getInternalId ();
45+ $ this ->cache [$ resource ->getName ()][$ documentId ] = $ status ;
46+ return ;
47+ }
48+
4249 if ($ resource ->getName () == Resource::TYPE_FILE || $ resource ->getName () == Resource::TYPE_DEPLOYMENT ) {
4350 /** @var File|Deployment $resource */
4451 $ resource ->setData ('' ); // Prevent Memory Leak
4552 }
4653
47- if ($ resource ->getName () == Resource::TYPE_DOCUMENT ) {
48- return ;
49- }
50-
5154 $ this ->cache [$ resource ->getName ()][$ resource ->getInternalId ()] = $ resource ;
5255 }
5356
@@ -75,14 +78,22 @@ public function addAll(array $resources): void
7578 */
7679 public function update (Resource $ resource ): void
7780 {
78- if (! in_array ($ resource ->getName (), $ this ->cache )) {
79- $ this ->add ($ resource );
80- }
81-
81+ // if documents then updating the status counter only
8282 if ($ resource ->getName () == Resource::TYPE_DOCUMENT ) {
83+ $ documentId = $ resource ->getInternalId ();
84+ if (!isset ($ this ->cache [$ resource ->getName ()][$ documentId ])) {
85+ $ this ->add ($ resource );
86+ } else {
87+ $ status = $ resource ->getStatus ();
88+ $ this ->cache [$ resource ->getName ()][$ documentId ] = $ status ;
89+ }
8390 return ;
8491 }
8592
93+ if (! in_array ($ resource ->getName (), $ this ->cache )) {
94+ $ this ->add ($ resource );
95+ }
96+
8697 $ this ->cache [$ resource ->getName ()][$ resource ->getInternalId ()] = $ resource ;
8798 }
8899
@@ -108,6 +119,11 @@ public function updateAll(array $resources): void
108119 */
109120 public function remove (Resource $ resource ): void
110121 {
122+ if ($ resource ->getName () === Resource::TYPE_DOCUMENT ) {
123+ if (! isset ($ this ->cache [$ resource ->getName ()][$ resource ->getInternalId ()])) {
124+ throw new \Exception ('Resource does not exist in cache ' );
125+ }
126+ }
111127 if (! in_array ($ resource , $ this ->cache [$ resource ->getName ()])) {
112128 throw new \Exception ('Resource does not exist in cache ' );
113129 }
@@ -133,7 +149,7 @@ public function get(string|Resource $resource): array
133149 /**
134150 * Get All Resources
135151 *
136- * @return array<string, array<string, Resource>>
152+ * @return array<string, array<string, Resource|string >>
137153 */
138154 public function getAll (): array
139155 {
0 commit comments