@next2d/cache 3.14.0 → 3.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/cache",
3
- "version": "3.14.0",
3
+ "version": "3.15.1",
4
4
  "description": "Next2D Cache Package",
5
5
  "author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
6
6
  "license": "MIT",
@@ -0,0 +1,17 @@
1
+ import type { CacheStore } from "../../CacheStore";
2
+ /**
3
+ * @description LRU上限($maxStoreSize)を超えた分のキャッシュを、参照が古い順に削除する。
4
+ * 削除したIDは$removeIdsに積み、worker側のGPUリソース(アトラス領域等)も
5
+ * 解放されるようにする。描画情報をworkerに送ったあとに呼ぶこと。
6
+ * Removes caches beyond the LRU limit ($maxStoreSize), least recently used
7
+ * first. Removed IDs are pushed to $removeIds so that the worker-side GPU
8
+ * resources (atlas regions etc.) are released as well. Call this after the
9
+ * render queue has been posted to the worker.
10
+ *
11
+ * @param {CacheStore} cache_store
12
+ * @param {Map} data_store
13
+ * @return {void}
14
+ * @method
15
+ * @protected
16
+ */
17
+ export declare const execute: (cache_store: CacheStore, data_store: Map<string, Map<string, any>>) => void;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @description LRU上限($maxStoreSize)を超えた分のキャッシュを、参照が古い順に削除する。
3
+ * 削除したIDは$removeIdsに積み、worker側のGPUリソース(アトラス領域等)も
4
+ * 解放されるようにする。描画情報をworkerに送ったあとに呼ぶこと。
5
+ * Removes caches beyond the LRU limit ($maxStoreSize), least recently used
6
+ * first. Removed IDs are pushed to $removeIds so that the worker-side GPU
7
+ * resources (atlas regions etc.) are released as well. Call this after the
8
+ * render queue has been posted to the worker.
9
+ *
10
+ * @param {CacheStore} cache_store
11
+ * @param {Map} data_store
12
+ * @return {void}
13
+ * @method
14
+ * @protected
15
+ */
16
+ export const execute = (cache_store, data_store) => {
17
+ cache_store.$overLimit = false;
18
+ if (cache_store.$maxStoreSize <= 0) {
19
+ return;
20
+ }
21
+ while (data_store.size > cache_store.$maxStoreSize) {
22
+ const oldestId = data_store.keys().next().value;
23
+ cache_store.removeById(oldestId);
24
+ cache_store.$removeIds.push(+oldestId);
25
+ }
26
+ };
@@ -31,21 +31,18 @@ export const execute = (cache_store, data_store, unique_key, key, value = null)
31
31
  }
32
32
  // set cache
33
33
  data.set(key, value);
34
- // LRU: 上限が設定されている場合(メインスレッドのopt-in)、
35
- // 触れたIDを最新に更新し、超過分を古い順にevictする。
36
- // evictは既存のタイマー削除と同じ経路(removeById + $removeIds)で
37
- // worker側のGPUリソースも解放される。上限0(デフォルト)では従来挙動のまま。
34
+ // LRU: 上限が設定されている場合(メインスレッドのopt-in)、触れたIDを最新に更新する。
35
+ // 上限を超えていても、ここでは削除しない。描画情報の生成中に削除すると、削除したIDを
36
+ // 同じ生成の中で作り直すことがあり、その場合 worker には「作り直しの描画」のあとに
37
+ // 「削除」が届いて、作り直したキャッシュが消える(メイン側はキャッシュ済みと認識した
38
+ // ままなので、以後その DisplayObject が描画されなくなる)。
39
+ // 超過分の削除は、描画情報を worker に送ったあとで evictOverLimit() が行う。
40
+ // 上限0(デフォルト)では従来挙動のまま。
38
41
  if (cache_store.$maxStoreSize > 0) {
39
42
  data_store.delete(unique_key);
40
43
  data_store.set(unique_key, data);
41
- while (data_store.size > cache_store.$maxStoreSize) {
42
- const oldestId = data_store.keys().next().value;
43
- // 触れたばかりのIDは削除しない(上限1未満の設定に対する安全弁)
44
- if (oldestId === unique_key) {
45
- break;
46
- }
47
- cache_store.removeById(oldestId);
48
- cache_store.$removeIds.push(+oldestId);
44
+ if (data_store.size > cache_store.$maxStoreSize) {
45
+ cache_store.$overLimit = true;
49
46
  }
50
47
  }
51
48
  };
@@ -69,6 +69,19 @@ export declare class CacheStore {
69
69
  * @public
70
70
  */
71
71
  $maxStoreSize: number;
72
+ /**
73
+ * @description エントリ数がLRU上限($maxStoreSize)を超えているかどうか。
74
+ * 毎フレーム参照されるため、関数を介さず直接参照する。
75
+ * trueのとき、描画情報をworkerに送ったあとで evictOverLimit() を呼ぶ。
76
+ * Whether the number of entries exceeds the LRU limit ($maxStoreSize).
77
+ * Read directly (not through a function) because it is checked every frame.
78
+ * When true, call evictOverLimit() after posting the render queue.
79
+ *
80
+ * @type {boolean}
81
+ * @default false
82
+ * @public
83
+ */
84
+ $overLimit: boolean;
72
85
  /**
73
86
  * @constructor
74
87
  */
@@ -141,6 +154,17 @@ export declare class CacheStore {
141
154
  * @public
142
155
  */
143
156
  removeTimerScheduledCache(): void;
157
+ /**
158
+ * @description LRU上限を超えた分のキャッシュを、参照が古い順に削除する。
159
+ * 描画情報をworkerに送ったあとに呼ぶこと。
160
+ * Removes caches beyond the LRU limit, least recently used first.
161
+ * Call this after the render queue has been posted to the worker.
162
+ *
163
+ * @returns {void}
164
+ * @method
165
+ * @public
166
+ */
167
+ evictOverLimit(): void;
144
168
  /**
145
169
  * @description 指定IDのキャッシュを削除する
146
170
  * Delete the cache for the specified ID
package/src/CacheStore.js CHANGED
@@ -10,6 +10,7 @@ import { execute as cacheStoreGenerateFilterKeysService } from "./CacheStore/ser
10
10
  import { execute as cacheStoreRemoveTimerService } from "./CacheStore/service/CacheStoreRemoveTimerService";
11
11
  import { execute as cacheStoreRemoveTimerScheduledCacheService } from "./CacheStore/service/CacheStoreRemoveTimerScheduledCacheService";
12
12
  import { execute as cacheStoreCancelRemoveTimerService } from "./CacheStore/service/CacheStoreCancelRemoveTimerService";
13
+ import { execute as cacheStoreEvictOverLimitService } from "./CacheStore/service/CacheStoreEvictOverLimitService";
13
14
  /**
14
15
  * @description キャッシュ管理クラス
15
16
  * Cache management class
@@ -120,6 +121,24 @@ export class CacheStore {
120
121
  writable: true,
121
122
  value: void 0
122
123
  });
124
+ /**
125
+ * @description エントリ数がLRU上限($maxStoreSize)を超えているかどうか。
126
+ * 毎フレーム参照されるため、関数を介さず直接参照する。
127
+ * trueのとき、描画情報をworkerに送ったあとで evictOverLimit() を呼ぶ。
128
+ * Whether the number of entries exceeds the LRU limit ($maxStoreSize).
129
+ * Read directly (not through a function) because it is checked every frame.
130
+ * When true, call evictOverLimit() after posting the render queue.
131
+ *
132
+ * @type {boolean}
133
+ * @default false
134
+ * @public
135
+ */
136
+ Object.defineProperty(this, "$overLimit", {
137
+ enumerable: true,
138
+ configurable: true,
139
+ writable: true,
140
+ value: void 0
141
+ });
123
142
  this._$pool = [];
124
143
  this._$store = new Map();
125
144
  this._$trash = new Map();
@@ -127,6 +146,7 @@ export class CacheStore {
127
146
  this.$removeIds = [];
128
147
  this.$removeCache = false;
129
148
  this.$maxStoreSize = 0;
149
+ this.$overLimit = false;
130
150
  }
131
151
  /**
132
152
  * @description 登録された全てのキャッシュをリセット・破棄する
@@ -210,6 +230,19 @@ export class CacheStore {
210
230
  removeTimerScheduledCache() {
211
231
  cacheStoreRemoveTimerScheduledCacheService(this, this._$trash);
212
232
  }
233
+ /**
234
+ * @description LRU上限を超えた分のキャッシュを、参照が古い順に削除する。
235
+ * 描画情報をworkerに送ったあとに呼ぶこと。
236
+ * Removes caches beyond the LRU limit, least recently used first.
237
+ * Call this after the render queue has been posted to the worker.
238
+ *
239
+ * @returns {void}
240
+ * @method
241
+ * @public
242
+ */
243
+ evictOverLimit() {
244
+ cacheStoreEvictOverLimitService(this, this._$store);
245
+ }
213
246
  /**
214
247
  * @description 指定IDのキャッシュを削除する
215
248
  * Delete the cache for the specified ID