@@ -67,158 +67,4 @@ main() => describe('CacheFactory', () {
67
67
68
68
69
69
});
70
-
71
-
72
- xdescribe ('LRU cache' , () {
73
-
74
- it ('should create cache with defined capacity' , inject (() {
75
- cache = $cacheFactory ('cache1' , {'capacity' : 5 });
76
- expect (cache.info ().size).toBe (0 );
77
-
78
- for (var i= 0 ; i< 5 ; i++ ) {
79
- cache.put ('id' + i, i);
80
- }
81
-
82
- expect (cache.info ().size).toBe (5 );
83
-
84
- cache.put ('id5' , 5 );
85
- expect (cache.info ().size).toBe (5 );
86
- cache.put ('id6' , 6 );
87
- expect (cache.info ().size).toBe (5 );
88
- }));
89
-
90
-
91
- describe ('eviction' , () {
92
-
93
- beforeEach (inject (() {
94
- cache = $cacheFactory ('cache1' , {'capacity' : 2 });
95
-
96
- cache.put ('id0' , 0 );
97
- cache.put ('id1' , 1 );
98
- }));
99
-
100
-
101
- it ('should kick out the first entry on put' , inject (() {
102
- cache.put ('id2' , 2 );
103
- expect (cache.get ('id0' )).toBeNull ();
104
- expect (cache.get ('id1' )).toBe (1 );
105
- expect (cache.get ('id2' )).toBe (2 );
106
- }));
107
-
108
-
109
- it ('should refresh an entry via get' , inject (() {
110
- cache.get ('id0' );
111
- cache.put ('id2' , 2 );
112
- expect (cache.get ('id0' )).toBe (0 );
113
- expect (cache.get ('id1' )).toBeNull ();
114
- expect (cache.get ('id2' )).toBe (2 );
115
- }));
116
-
117
-
118
- it ('should refresh an entry via put' , inject (() {
119
- cache.put ('id0' , '00' );
120
- cache.put ('id2' , 2 );
121
- expect (cache.get ('id0' )).toBe ('00' );
122
- expect (cache.get ('id1' )).toBeNull ();
123
- expect (cache.get ('id2' )).toBe (2 );
124
- }));
125
-
126
-
127
- it ('should not purge an entry if another one was removed' , inject (() {
128
- cache.remove ('id1' );
129
- cache.put ('id2' , 2 );
130
- expect (cache.get ('id0' )).toBe (0 );
131
- expect (cache.get ('id1' )).toBeNull ();
132
- expect (cache.get ('id2' )).toBe (2 );
133
- }));
134
-
135
-
136
- it ('should purge the next entry if the stalest one was removed' , inject (() {
137
- cache.remove ('id0' );
138
- cache.put ('id2' , 2 );
139
- cache.put ('id3' , 3 );
140
- expect (cache.get ('id0' )).toBeNull ();
141
- expect (cache.get ('id1' )).toBeNull ();
142
- expect (cache.get ('id2' )).toBe (2 );
143
- expect (cache.get ('id3' )).toBe (3 );
144
- }));
145
-
146
-
147
- it ('should correctly recreate the linked list if all cache entries were removed' , inject (() {
148
- cache.remove ('id0' );
149
- cache.remove ('id1' );
150
- cache.put ('id2' , 2 );
151
- cache.put ('id3' , 3 );
152
- cache.put ('id4' , 4 );
153
- expect (cache.get ('id0' )).toBeNull ();
154
- expect (cache.get ('id1' )).toBeNull ();
155
- expect (cache.get ('id2' )).toBeNull ();
156
- expect (cache.get ('id3' )).toBe (3 );
157
- expect (cache.get ('id4' )).toBe (4 );
158
- }));
159
-
160
-
161
- it ('should blow away the entire cache via removeAll and start evicting when full' , inject (() {
162
- cache.put ('id0' , 0 );
163
- cache.put ('id1' , 1 );
164
- cache.removeAll ();
165
-
166
- cache.put ('id2' , 2 );
167
- cache.put ('id3' , 3 );
168
- cache.put ('id4' , 4 );
169
-
170
- expect (cache.info ().size).toBe (2 );
171
- expect (cache.get ('id0' )).toBeNull ();
172
- expect (cache.get ('id1' )).toBeNull ();
173
- expect (cache.get ('id2' )).toBeNull ();
174
- expect (cache.get ('id3' )).toBe (3 );
175
- expect (cache.get ('id4' )).toBe (4 );
176
- }));
177
-
178
-
179
- it ('should correctly refresh and evict items if operations are chained' , inject (() {
180
- cache = $cacheFactory ('cache2' , {'capacity' : 3 });
181
-
182
- cache.put ('id0' , 0 ); //0
183
- cache.put ('id1' , 1 ); //1,0
184
- cache.put ('id2' , 2 ); //2,1,0
185
- cache.get ('id0' ); //0,2,1
186
- cache.put ('id3' , 3 ); //3,0,2
187
- cache.put ('id0' , 9 ); //0,3,2
188
- cache.put ('id4' , 4 ); //4,0,3
189
-
190
- expect (cache.get ('id3' )).toBe (3 );
191
- expect (cache.get ('id0' )).toBe (9 );
192
- expect (cache.get ('id4' )).toBe (4 );
193
-
194
- cache.remove ('id0' ); //4,3
195
- cache.remove ('id3' ); //4
196
- cache.put ('id5' , 5 ); //5,4
197
- cache.put ('id6' , 6 ); //6,5,4
198
- cache.get ('id4' ); //4,6,5
199
- cache.put ('id7' , 7 ); //7,4,6
200
-
201
- expect (cache.get ('id0' )).toBeNull ();
202
- expect (cache.get ('id1' )).toBeNull ();
203
- expect (cache.get ('id2' )).toBeNull ();
204
- expect (cache.get ('id3' )).toBeNull ();
205
- expect (cache.get ('id4' )).toBe (4 );
206
- expect (cache.get ('id5' )).toBeNull ();
207
- expect (cache.get ('id6' )).toBe (6 );
208
- expect (cache.get ('id7' )).toBe (7 );
209
-
210
- cache.removeAll ();
211
- cache.put ('id0' , 0 ); //0
212
- cache.put ('id1' , 1 ); //1,0
213
- cache.put ('id2' , 2 ); //2,1,0
214
- cache.put ('id3' , 3 ); //3,2,1
215
-
216
- expect (cache.info ().size).toBe (3 );
217
- expect (cache.get ('id0' )).toBeNull ();
218
- expect (cache.get ('id1' )).toBe (1 );
219
- expect (cache.get ('id2' )).toBe (2 );
220
- expect (cache.get ('id3' )).toBe (3 );
221
- }));
222
- });
223
- });
224
70
});
0 commit comments