Commit 57ecae22a7b837d486bb03eda944736780ce0868

David Turner 2003-12-19T21:23:58

new version of the cache sub-system - still under debugging

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
diff --git a/include/freetype/cache/ftccache.h b/include/freetype/cache/ftccache.h
index 701b13e..60191bc 100644
--- a/include/freetype/cache/ftccache.h
+++ b/include/freetype/cache/ftccache.h
@@ -20,9 +20,6 @@
 #define __FTCCACHE_H__
 
 
-/* define to allow cache lookup inlining */
-#define  FTC_CACHE_USE_INLINE
-
 
 FT_BEGIN_HEADER
 
@@ -30,14 +27,7 @@ FT_BEGIN_HEADER
   typedef struct FTC_CacheRec_*  FTC_Cache;
 
   /* handle to cache class */
-  typedef const struct FTC_Cache_ClassRec_*  FTC_Cache_Class;
-
-  /* handle to cache node family */
-  typedef struct FTC_FamilyRec_*  FTC_Family;
-
-  /* handle to cache root query */
-  typedef struct FTC_QueryRec_*  FTC_Query;
-
+  typedef const struct FTC_CacheClassRec_*  FTC_CacheClass;
 
   /*************************************************************************/
   /*************************************************************************/
@@ -66,7 +56,7 @@ FT_BEGIN_HEADER
     FTC_Node   mru_prev;     /* circular mru list pointer           */
     FTC_Node   link;         /* used for hashing                    */
     FT_UInt32  hash;         /* used for hashing too                */
-    FT_UShort  fam_index;    /* index of family the node belongs to */
+    FT_UShort  cache_index;  /* index of cache the node belongs to  */
     FT_Short   ref_count;    /* reference count for this node       */
 
   } FTC_NodeRec;
@@ -83,108 +73,72 @@ FT_BEGIN_HEADER
   /* cache sub-system internals.                                           */
   /*                                                                       */
 
-  /* can be used as a FTC_Node_DoneFunc */
-  FT_EXPORT( void )
-  ftc_node_done( FTC_Node   node,
-                 FTC_Cache  cache );
-
   /* reserved for manager's use */
   FT_EXPORT( void )
   ftc_node_destroy( FTC_Node     node,
                     FTC_Manager  manager );
 
 
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                   CACHE QUERY DEFINITIONS                     *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-
-  /* A structure modelling a cache node query.  The following fields must  */
-  /* all be set by the @FTC_Family_CompareFunc method of a cache's family  */
-  /* list.                                                                 */
-  /*                                                                       */
-  typedef struct  FTC_QueryRec_
-  {
-    FTC_Family  family;
-    FT_UFast    hash;
-
-  } FTC_QueryRec;
-
-
-#define FTC_QUERY( x )    ( (FTC_Query)(x) )
-#define FTC_QUERY_P( x )  ( (FTC_Query*)(x) )
-
 
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
-  /*****                   CACHE FAMILY DEFINITIONS                    *****/
+  /*****                       CACHE DEFINITIONS                       *****/
   /*****                                                               *****/
   /*************************************************************************/
   /*************************************************************************/
 
-  typedef struct  FTC_FamilyRec_
-  {
-    FT_LruNodeRec  lru;
-    FTC_Cache      cache;
-    FT_UInt        num_nodes;
-    FT_UInt        fam_index;
+  /* initialize a new cache node */
+  typedef FT_Error    (*FTC_Node_NewFunc)( FTC_Node    *pnode,
+                                           FT_Pointer   query,
+                                           FTC_Cache    cache );
 
-  } FTC_FamilyRec;
+  typedef FT_ULong    (*FTC_Node_WeightFunc)( FTC_Node   node,
+                                              FTC_Cache  cache );
 
+  /* compare a node to a given key pair */
+  typedef FT_Bool     (*FTC_Node_CompareFunc)( FTC_Node    node,
+                                               FT_Pointer  key,
+                                               FTC_Cache   cache );
 
-#define FTC_FAMILY( x )    ( (FTC_Family)(x) )
-#define FTC_FAMILY_P( x )  ( (FTC_Family*)(x) )
 
+  typedef void        (*FTC_Node_FreeFunc)( FTC_Node   node,
+                                            FTC_Cache  cache );
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* These functions are exported so that they can be called from          */
-  /* user-provided cache classes; otherwise, they are really part of the   */
-  /* cache sub-system internals.                                           */
-  /*                                                                       */
+  typedef FT_Error    (*FTC_Cache_InitFunc)( FTC_Cache   cache );
 
-  /* must be called by any FTC_Node_InitFunc routine */
-  FT_EXPORT( FT_Error )
-  ftc_family_init( FTC_Family  family,
-                   FTC_Query   query,
-                   FTC_Cache   cache );
+  typedef void        (*FTC_Cache_DoneFunc)( FTC_Cache   cache );
 
 
-  /* can be used as a FTC_Family_DoneFunc; otherwise, must be called */
-  /* by any family finalizer function                                */
-  FT_EXPORT( void )
-  ftc_family_done( FTC_Family  family );
+  typedef struct FTC_CacheClassRec_
+  {
+    FTC_Node_NewFunc        node_new;
+    FTC_Node_WeightFunc     node_weight;
+    FTC_Node_CompareFunc    node_compare;
+    FTC_Node_CompareFunc    node_remove_faceid;
+    FTC_Node_FreeFunc       node_free;
 
+    FT_UInt                 cache_size;
+    FTC_Cache_InitFunc      cache_init;
+    FTC_Cache_DoneFunc      cache_done;
 
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                       CACHE DEFINITIONS                       *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
+  } FTC_CacheClassRec;
 
   /* each cache really implements a dynamic hash table to manage its nodes */
   typedef struct  FTC_CacheRec_
   {
-    FTC_Manager          manager;
-    FT_Memory            memory;
-    FTC_Cache_Class      clazz;
-
-    FT_UInt              cache_index;  /* in manager's table         */
-    FT_Pointer           cache_data;   /* used by cache node methods */
-
     FT_UFast             p;
     FT_UFast             mask;
     FT_Long              slack;
     FTC_Node*            buckets;
 
-    FT_LruList_ClassRec  family_class;
-    FT_LruList           families;
+    FTC_CacheClassRec    clazz;      /* local copy, for speed */
+
+    FTC_Manager          manager;
+    FT_Memory            memory;
+    FT_UInt              index;  /* in manager's table         */
+
+    FTC_CacheClass       org_class;  /* original class pointer */
 
   } FTC_CacheRec;
 
@@ -193,105 +147,38 @@ FT_BEGIN_HEADER
 #define FTC_CACHE_P( x )  ( (FTC_Cache*)(x) )
 
 
-  /* initialize a given cache */
-  typedef FT_Error
-  (*FTC_Cache_InitFunc)( FTC_Cache  cache );
-
-  /* clear a cache */
-  typedef void
-  (*FTC_Cache_ClearFunc)( FTC_Cache  cache );
-
-  /* finalize a given cache */
-  typedef void
-  (*FTC_Cache_DoneFunc)( FTC_Cache  cache );
-
-
-  typedef FT_Error
-  (*FTC_Family_InitFunc)( FTC_Family  family,
-                          FTC_Query   query,
-                          FTC_Cache   cache );
-
-  typedef FT_Int
-  (*FTC_Family_CompareFunc)( FTC_Family  family,
-                             FTC_Query   query );
-
-  typedef void
-  (*FTC_Family_DoneFunc)( FTC_Family  family,
-                          FTC_Cache   cache );
-
-  /* initialize a new cache node */
-  typedef FT_Error
-  (*FTC_Node_InitFunc)( FTC_Node    node,
-                        FT_Pointer  type,
-                        FTC_Cache   cache );
-
-  /* compute the weight of a given cache node */
-  typedef FT_ULong
-  (*FTC_Node_WeightFunc)( FTC_Node   node,
-                          FTC_Cache  cache );
-
-  /* compare a node to a given key pair */
-  typedef FT_Bool
-  (*FTC_Node_CompareFunc)( FTC_Node    node,
-                           FT_Pointer  key,
-                           FTC_Cache   cache );
-
-  /* finalize a given cache node */
-  typedef void
-  (*FTC_Node_DoneFunc)( FTC_Node   node,
-                        FTC_Cache  cache );
-
-
-  typedef struct  FTC_Cache_ClassRec_
-  {
-    FT_UInt                 cache_size;
-    FTC_Cache_InitFunc      cache_init;
-    FTC_Cache_ClearFunc     cache_clear;
-    FTC_Cache_DoneFunc      cache_done;
-
-    FT_UInt                 family_size;
-    FTC_Family_InitFunc     family_init;
-    FTC_Family_CompareFunc  family_compare;
-    FTC_Family_DoneFunc     family_done;
-
-    FT_UInt                 node_size;
-    FTC_Node_InitFunc       node_init;
-    FTC_Node_WeightFunc     node_weight;
-    FTC_Node_CompareFunc    node_compare;
-    FTC_Node_DoneFunc       node_done;
-
-  } FTC_Cache_ClassRec;
-
-
-  /* */
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* These functions are exported so that they can be called from          */
-  /* user-provided cache classes; otherwise, they are really part of the   */
-  /* cache sub-system internals.                                           */
-  /*                                                                       */
-
-  /* can be used directly as FTC_Cache_DoneFunc(), or called by custom */
-  /* cache finalizers                                                  */
-  FT_EXPORT( void )
-  ftc_cache_done( FTC_Cache  cache );
+ /* default cache initialize */
+  FT_EXPORT( FT_Error )
+  FTC_Cache_Init( FTC_Cache       cache );
 
-  /* can be used directly as FTC_Cache_ClearFunc(), or called by custom */
-  /* cache clear routines                                               */
+ /* default cache finalizer */
   FT_EXPORT( void )
-  ftc_cache_clear( FTC_Cache  cache );
+  FTC_Cache_Done( FTC_Cache  cache );
 
-  /* initalize the hash table within the cache */
+ /* call this function to lookup the cache. if no corresponding
+  * node is found, a new one is automatically created. This function
+  * is capable of flushing the cache adequately to make room for the
+  * new cache object.
+  */
   FT_EXPORT( FT_Error )
-  ftc_cache_init( FTC_Cache  cache );
-
-  /* can be called when the key's hash value has been computed */
-  FT_EXPORT( FT_Error )
-  ftc_cache_lookup( FTC_Cache  cache,
-                    FTC_Query  query,
-                    FTC_Node  *anode );
+  FTC_Cache_Lookup( FTC_Cache   cache,
+                    FT_UInt32   hash,
+                    FT_Pointer  query,
+                    FTC_Node   *anode );
+
+ /* remove all nodes that relate to a given face_id. This is useful
+  * when un-installing fonts. Note that if a cache node relates to
+  * the face_id, but is locked (i.e. has 'ref_count > 0'), the node
+  * will _not_ be destroyed, but its internal face_id reference will
+  * be modified.
+  *
+  * the end result will be that the node will never come back
+  * in further lookup requests, and will be flushed on demand from
+  * the cache normally when its reference count reaches 0
+  */
+  FT_EXPORT( void )
+  FTC_Cache_RemoveFaceID( FTC_Cache    cache,
+                          FTC_FaceID   face_id );
 
  /* */
 
diff --git a/include/freetype/cache/ftcglyph.h b/include/freetype/cache/ftcglyph.h
index ee72c33..3b7510d 100644
--- a/include/freetype/cache/ftcglyph.h
+++ b/include/freetype/cache/ftcglyph.h
@@ -16,13 +16,84 @@
 /***************************************************************************/
 
 
+  /*
+   *
+   *  FTC_GCache is an _abstract_ cache object optimized to store glyph
+   *  data. It works as follows:
+   *
+   *   - it manages FTC_GNode objects. Each one of them can hold one or more
+   *     glyph "items". Item types are not specified in the FTC_GCache but in
+   *     classes that extend it
+   *
+   *   - glyph attributes, like face_id, character size, render mode, etc..
+   *     can be grouped in abstract "glyph families". This avoids storing
+   *     the attributes within the FTC_GCache, since it is likely that many
+   *     FTC_GNodes will belong to the same family in typical uses
+   *
+   *   - each FTC_GNode is thus a FTC_Node with two additionnal fields:
+   *
+   *       * gindex :: a glyph index, or the first index in a glyph range
+   *       * family :: a pointer to a glyph "family"
+   *
+   *   - Family types are not fully specific in the FTC_Family type, but
+   *     by classes that extend it.
+   *
+   *  Note that both FTC_ImageCache and FTC_SBitCache extend FTC_GCache. They
+   *  share an FTC_Family sub-class called FTC_BasicFamily which is used to
+   *  store the following data:  face_id, pixel/point sizes, load flags.
+   *  for more details, see the file "src/cache/ftcbasic.c"
+   *
+   *  Client applications can extend FTC_GNode with their own FTC_GNode
+   *  and FTC_Family sub-classes to implement more complex caches (e.g.
+   *  handling automatic synthetis, like obliquing & emboldening, colored
+   *  glyphs, etc...)
+   *
+   *  See also the FTC_ICache & FTC_SCache classes in "ftcimage.h" and
+   *  "ftcsbits.h", which both extend FTC_GCache with additionnal
+   *  optimizations.
+   *
+   *
+   *  a typical FTC_GCache implementation must provide at least the following:
+   *  
+   *  - FTC_GNode sub-class, e.g. MyNode, with relevant methods, i.e:
+   *        my_node_new            ( must call FTC_GNode_Init )
+   *        my_node_free           ( must call FTC_GNode_Done )
+   *        my_node_compare        ( must call FTC_GNode_Compare )
+   *        my_node_remove_faceid  ( must call ftc_gnode_unselect in case 
+   *                                 of match )
+   *
+   *
+   *  - FTC_Family sub-class, e.g. MyFamily, with relevant methods, e.g.:
+   *        my_family_compare
+   *        my_family_init
+   *        my_family_reset (optional)
+   *        my_family_done
+   *
+   *  - FTC_GQuery sub-class, e.g. MyQuery, to hold cache-specific query
+   *    data.
+   *
+   *  - provide constant structures for a FTC_GNodeClass
+   *
+   *  - MyCacheNew() can be implemented easily as a call to the convenience
+   *    function FTC_GCache_New
+   *
+   *  - implement MyCacheLookup with a call to FTC_GCache_Lookup. This
+   *    function will automatically:
+   *
+   *      - search for the corresponding family in the cache, or create
+   *        a new one if necessary. put it in FTC_GQUERY(myquery).family
+   *
+   *      - call FTC_Cache_Lookup
+   *
+   *    if it returns NULL, you should create a new node, then call
+   *    ftc_cache_add as usual.
+   */
+
   /*************************************************************************/
   /*                                                                       */
   /* Important: The functions defined in this file are only used to        */
   /*            implement an abstract glyph cache class.  You need to      */
   /*            provide additional logic to implement a complete cache.    */
-  /*            For example, see `ftcimage.h' and `ftcimage.c' which       */
-  /*            implement a FT_Glyph cache based on this code.             */
   /*                                                                       */
   /*************************************************************************/
 
@@ -47,98 +118,63 @@
 
 
 #include <ft2build.h>
-#include FT_CACHE_H
-#include FT_CACHE_MANAGER_H
+#include FT_CACHE_INTERNAL_MANAGER_H
 
 
 FT_BEGIN_HEADER
 
 
-  /* each glyph set is characterized by a "glyph set type" which must be */
-  /* defined by sub-classes                                              */
-  typedef struct FTC_GlyphFamilyRec_*  FTC_GlyphFamily;
-
-  /* handle to a glyph cache node */
-  typedef struct FTC_GlyphNodeRec_*  FTC_GlyphNode;
-
-
-  /* size should be 24 + chunk size on 32-bit machines;                 */
-  /* note that the node's hash is ((gfam->hash << 16) | glyph_index) -- */
-  /* this _must_ be set properly by the glyph node initializer          */
-  /*                                                                    */
-  typedef struct  FTC_GlyphNodeRec_
+ /*
+  *  we can group glyph in "families". Each family correspond to a
+  *  given face id, character size, transform, etc...
+  *
+  *  families are implemented as MRU list nodes. They are reference-counted
+  */
+  
+  typedef struct  FTC_FamilyRec_
   {
-    FTC_NodeRec   node;
-    FT_UShort     item_count;
-    FT_UShort     item_start;
+    FTC_MruNode       mrunode;
+    FT_UInt           num_nodes;   /* current number of nodes in this family */
+    FTC_MruListClass  clazz;
+  
+  } FTC_FamilyRec, *FTC_Family;
 
-  } FTC_GlyphNodeRec;
+#define  FTC_FAMILY(x)    ( (FTC_Family)(x) )
+#define  FTC_FAMILY_P(x)  ( (FTC_Family*)(x) )
 
 
-#define FTC_GLYPH_NODE( x )    ( (FTC_GlyphNode)(x) )
-#define FTC_GLYPH_NODE_P( x )  ( (FTC_GlyphNode*)(x) )
-
-
-  typedef struct  FTC_GlyphQueryRec_
+  typedef struct  FTC_GNodeRec_
   {
-    FTC_QueryRec  query;
-    FT_UInt       gindex;
+    FTC_NodeRec      node;
+    FTC_Family       family;
+    FT_UInt          gindex;
 
-  } FTC_GlyphQueryRec, *FTC_GlyphQuery;
+  } FTC_GNodeRec, *FTC_GNode;
 
+#define FTC_GNODE( x )    ( (FTC_GNode)(x) )
+#define FTC_GNODE_P( x )  ( (FTC_GNode*)(x) )
 
-#define FTC_GLYPH_QUERY( x )  ( (FTC_GlyphQuery)(x) )
 
-
-  /* a glyph set is used to categorize glyphs of a given type */
-  typedef struct  FTC_GlyphFamilyRec_
+  typedef struct  FTC_GQueryRec_
   {
-    FTC_FamilyRec  family;
-    FT_UInt32      hash;
-    FT_UInt        item_total;   /* total number of glyphs in family */
-    FT_UInt        item_count;   /* number of glyph items per node   */
-
-  } FTC_GlyphFamilyRec;
+    FT_UInt      gindex;
+    FTC_Family   family;
 
+  } FTC_GQueryRec, *FTC_GQuery;
 
-#define FTC_GLYPH_FAMILY( x )         ( (FTC_GlyphFamily)(x) )
-#define FTC_GLYPH_FAMILY_P( x )       ( (FTC_GlyphFamily*)(x) )
+#define FTC_GQUERY( x )  ( (FTC_GQuery)(x) )
 
-#define FTC_GLYPH_FAMILY_MEMORY( x )  FTC_FAMILY(x)->cache->memory
 
 
   /* each glyph node contains a 'chunk' of glyph items; */
   /* translate a glyph index into a chunk index         */
-#define FTC_GLYPH_FAMILY_CHUNK( gfam, gindex )                  \
-          ( ( gindex ) / FTC_GLYPH_FAMILY( gfam )->item_count )
+#define FTC_FAMILY_CHUNK( gfam, gindex )                  \
+          ( ( gindex ) / FTC_FAMILY( gfam )->item_count )
 
   /* find a glyph index's chunk, and return its start index */
-#define FTC_GLYPH_FAMILY_START( gfam, gindex )       \
-          ( FTC_GLYPH_FAMILY_CHUNK( gfam, gindex ) * \
-            FTC_GLYPH_FAMILY( gfam )->item_count )
-
-  /* compute a glyph request's hash value */
-#define FTC_GLYPH_FAMILY_HASH( gfam, gindex )                          \
-          ( (FT_UFast)(                                                \
-              ( FTC_GLYPH_FAMILY( gfam )->hash << 16 ) |               \
-              ( FTC_GLYPH_FAMILY_CHUNK( gfam, gindex ) & 0xFFFFU ) ) )
-
-  /* must be called in an FTC_Family_CompareFunc to update the query */
-  /* whenever a glyph set is matched in the lookup, or when it       */
-  /* is created                                                      */
-#define FTC_GLYPH_FAMILY_FOUND( gfam, gquery )                            \
-          do                                                              \
-          {                                                               \
-            FTC_QUERY( gquery )->family = FTC_FAMILY( gfam );             \
-            FTC_QUERY( gquery )->hash =                                   \
-              FTC_GLYPH_FAMILY_HASH( gfam,                                \
-                                     FTC_GLYPH_QUERY( gquery )->gindex ); \
-          } while ( 0 )
-
-  /* retrieve glyph index of glyph node */
-#define FTC_GLYPH_NODE_GINDEX( x )                                  \
-          ( (FT_UInt)( FTC_GLYPH_NODE( x )->node.hash & 0xFFFFU ) )
-
+#define FTC_FAMILY_START( gfam, gindex )       \
+          ( FTC_FAMILY_CHUNK( gfam, gindex ) * \
+            FTC_FAMILY( gfam )->item_count )
 
   /*************************************************************************/
   /*                                                                       */
@@ -149,36 +185,78 @@ FT_BEGIN_HEADER
 
   /* must be called by derived FTC_Node_InitFunc routines */
   FT_EXPORT( void )
-  ftc_glyph_node_init( FTC_GlyphNode    node,
-                       FT_UInt          gindex,  /* glyph index for node */
-                       FTC_GlyphFamily  gfam );
+  FTC_GNode_Init( FTC_GNode    node,
+                  FT_UInt      gindex,  /* glyph index for node */
+                  FTC_Family   family );
 
   /* returns TRUE iff the query's glyph index correspond to the node;  */
   /* this assumes that the "family" and "hash" fields of the query are */
   /* already correctly set                                             */
   FT_EXPORT( FT_Bool )
-  ftc_glyph_node_compare( FTC_GlyphNode   gnode,
-                          FTC_GlyphQuery  gquery );
+  FTC_GNode_Compare( FTC_GNode   gnode,
+                     FTC_GQuery  gquery );
+
+ /* call this function to clear a node's family. this is necessary
+  * to implement the "node_remove_faceid" cache method correctly
+  */
+  FT_EXPORT( void )
+  FTC_GNode_UnselectFamily( FTC_GNode   gnode,
+                            FTC_Cache   cache );
 
   /* must be called by derived FTC_Node_DoneFunc routines */
   FT_EXPORT( void )
-  ftc_glyph_node_done( FTC_GlyphNode  node,
-                       FTC_Cache      cache );
+  FTC_GNode_Done( FTC_GNode  node,
+                  FTC_Cache      cache );
+
+
+  typedef struct FTC_GCacheRec_
+  {
+    FTC_CacheRec       cache;
+    FTC_MruListRec     families;
+
+  } FTC_GCacheRec, *FTC_GCache;
 
 
-  /* must be called by derived FTC_Family_InitFunc; */
-  /* calls "ftc_family_init"                        */
+#define FTC_GCACHE(x)  ((FTC_GCache)(x))
+
+
+ /* can be used as @FTC_Cache_InitFunc */
   FT_EXPORT( FT_Error )
-  ftc_glyph_family_init( FTC_GlyphFamily  gfam,
-                         FT_UInt32        hash,
-                         FT_UInt          item_count,
-                         FT_UInt          item_total,
-                         FTC_GlyphQuery   gquery,
-                         FTC_Cache        cache );
+  FTC_GCache_Init( FTC_GCache     cache );
 
+
+ /* can be used as @FTC_Cache_DoneFunc */
   FT_EXPORT( void )
-  ftc_glyph_family_done( FTC_GlyphFamily  gfam );
+  FTC_GCache_Done( FTC_GCache  cache );
+
+
+ /* the glyph cache class adds fields for the family implementation */
+  typedef struct FTC_GCacheClassRec_
+  {
+    FTC_CacheClassRec  clazz;
+    FTC_MruListClass   family_class;
+
+  } FTC_GCacheClassRec;
 
+  typedef const FTC_GCacheClassRec*   FTC_GCacheClass;
+
+#define  FTC_GCACHE_CLASS(x)  ((FTC_GCacheClass)(x))
+
+#define  FTC_CACHE__GCACHE_CLASS(x)  FTC_GCACHE_CLASS( FTC_CACHE(x)->org_class )
+
+
+ /* convenience function. use instead of FTC_Manager_Register_Cache */
+  FT_EXPORT( FT_Error )
+  FTC_GCache_New( FTC_Manager       manager,
+                  FTC_GCacheClass   clazz,
+                  FTC_GCache       *acache );
+
+  FT_EXPORT( FT_Error )
+  FTC_GCache_Lookup( FTC_GCache   cache,
+                     FT_UInt32    hash,
+                     FT_UInt      gindex,
+                     FTC_GQuery   query,
+                     FTC_Node    *anode );
 
   /* */
  
diff --git a/include/freetype/cache/ftcimage.h b/include/freetype/cache/ftcimage.h
index 2d0b780..69ed9e5 100644
--- a/include/freetype/cache/ftcimage.h
+++ b/include/freetype/cache/ftcimage.h
@@ -2,7 +2,7 @@
 /*                                                                         */
 /*  ftcimage.h                                                             */
 /*                                                                         */
-/*    FreeType Image cache (specification).                                */
+/*    FreeType Generic Image cache (specification)                         */
 /*                                                                         */
 /*  Copyright 2000-2001, 2002, 2003 by                                     */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
@@ -16,6 +16,15 @@
 /***************************************************************************/
 
 
+ /*
+  *  FTC_ICache is an _abstract_ cache used to store a single FT_Glyph
+  *  image per cache node.
+  *
+  *  FTC_ICache extends FTC_GCache. For an implementation example,
+  *  see FTC_ImageCache in "src/cache/ftbasic.c"
+  *
+  */
+  
   /*************************************************************************/
   /*                                                                       */
   /* Each image cache really manages FT_Glyph objects.                     */
@@ -29,284 +38,64 @@
 
 #include <ft2build.h>
 #include FT_CACHE_H
-
+#include FT_CACHE_INTERNAL_GLYPH_H
 
 FT_BEGIN_HEADER
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Section>                                                             */
-  /*    cache_subsystem                                                    */
-  /*                                                                       */
-  /*************************************************************************/
-
-
-  /*************************************************************************/
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                       IMAGE CACHE OBJECT                      *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-  /*************************************************************************/
-
-
- /**************************************************************************
-  *
-  * @struct:
-  *   FTC_ImageTypeRec
-  *
-  * @description:
-  *   A simple structure used to describe the type of glyph image to be
-  *   loaded into the cache.
-  *
-  * @fields:
-  *   font  :: An @FTC_FontRec used to describe the glyph's face and size.
-  *
-  *   flags :: The load flags to be applied when loading the glyph; see
-  *            the @FT_LOAD_XXX constants for details.
-  *
-  * @note:
-  *   This type completely replaces the @FTC_Image_Desc structure which is
-  *   now obsolete.
-  */
-  typedef struct  FTC_ImageTypeRec_
+  /* the FT_Glyph image node type - we store only 1 glyph per node */
+  typedef struct  FTC_INodeRec_
   {
-    FTC_FontRec  font;
-    FT_Int32     flags;
+    FTC_GNodeRec  gnode;
+    FT_Glyph      glyph;
 
-  } FTC_ImageTypeRec;
-
-  typedef struct FTC_ImageTypeRec_*   FTC_ImageType;
-
- /* */
+  } FTC_INodeRec, *FTC_INode;
 
-#define FTC_IMAGE_TYPE_COMPARE( d1, d2 )                    \
-          ( FTC_FONT_COMPARE( &(d1)->font, &(d2)->font ) && \
-            (d1)->flags == (d2)->flags                   )
+#define FTC_INODE( x )         ( (FTC_INode)( x ) )
+#define FTC_INODE_GINDEX( x )  FTC_GNODE(x)->gindex
+#define FTC_INODE_FAMILY( x )  FTC_GNODE(x)->family
 
-#define FTC_IMAGE_TYPE_HASH( d )                    \
-          (FT_UFast)( FTC_FONT_HASH( &(d)->font ) ^ \
-                      ( (d)->flags << 4 )         )
+  typedef FT_Error  (*FTC_IFamily_LoadGlyphFunc)( FTC_Family   family,
+                                                  FT_UInt      gindex,
+                                                  FTC_Cache    cache,
+                                                  FT_Glyph    *aglyph );
 
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Type>                                                                */
-  /*    FTC_ImageCache                                                     */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    A handle to an glyph image cache object.  They are designed to     */
-  /*    hold many distinct glyph images while not exceeding a certain      */
-  /*    memory threshold.                                                  */
-  /*                                                                       */
-  typedef struct FTC_ImageCacheRec_*  FTC_ImageCache;
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    FTC_ImageCache_New                                                 */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Creates a new glyph image cache.                                   */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    manager :: The parent manager for the image cache.                 */
-  /*                                                                       */
-  /* <Output>                                                              */
-  /*    acache  :: A handle to the new glyph image cache object.           */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
-  FT_EXPORT( FT_Error )
-  FTC_ImageCache_New( FTC_Manager      manager,
-                      FTC_ImageCache  *acache );
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    FTC_ImageCache_Lookup                                              */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Retrieves a given glyph image from a glyph image cache.            */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    cache  :: A handle to the source glyph image cache.                */
-  /*                                                                       */
-  /*    type   :: A pointer to a glyph image type descriptor.              */
-  /*                                                                       */
-  /*    gindex :: The glyph index to retrieve.                             */
-  /*                                                                       */
-  /* <Output>                                                              */
-  /*    aglyph :: The corresponding @FT_Glyph object.  0 in case of        */
-  /*              failure.                                                 */
-  /*                                                                       */
-  /*    anode  :: Used to return the address of of the corresponding cache */
-  /*              node after incrementing its reference count (see note    */
-  /*              below).                                                  */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    The returned glyph is owned and managed by the glyph image cache.  */
-  /*    Never try to transform or discard it manually!  You can however    */
-  /*    create a copy with @FT_Glyph_Copy and modify the new one.          */
-  /*                                                                       */
-  /*    If "anode" is _not_ NULL, it receives the address of the cache     */
-  /*    node containing the glyph image, after increasing its reference    */
-  /*    count.  This ensures that the node (as well as the FT_Glyph) will  */
-  /*    always be kept in the cache until you call @FTC_Node_Unref to      */
-  /*    "release" it.                                                      */
-  /*                                                                       */
-  /*    If "anode" is NULL, the cache node is left unchanged, which means  */
-  /*    that the FT_Glyph could be flushed out of the cache on the next    */
-  /*    call to one of the caching sub-system APIs.  Don't assume that it  */
-  /*    is persistent!                                                     */
-  /*                                                                       */
-  FT_EXPORT( FT_Error )
-  FTC_ImageCache_Lookup( FTC_ImageCache  cache,
-                         FTC_ImageType   type,
-                         FT_UInt         gindex,
-                         FT_Glyph       *aglyph,
-                         FTC_Node       *anode );
-
-  /* */
-
-#define ftc_image_format( x )  ( (x) & 7 )
-
-
-#define ftc_image_format_bitmap    0x0000
-#define ftc_image_format_outline   0x0001
-
-#define ftc_image_format_mask      0x000F
-
-#define ftc_image_flag_monochrome  0x0010
-#define ftc_image_flag_unhinted    0x0020
-#define ftc_image_flag_autohinted  0x0040
-#define ftc_image_flag_unscaled    0x0080
-#define ftc_image_flag_no_sbits    0x0100
-
-  /* monochrome bitmap */
-#define ftc_image_mono             ftc_image_format_bitmap | \
-                                   ftc_image_flag_monochrome
-
-  /* anti-aliased bitmap */
-#define ftc_image_grays            ftc_image_format_bitmap
-
-  /* scaled outline */
-#define ftc_image_outline          ftc_image_format_outline
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Struct>                                                              */
-  /*    FTC_Image_Desc                                                     */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    THIS TYPE IS DEPRECATED.  Use @FTC_ImageTypeRec instead.           */
-  /*                                                                       */
-  /*    A simple structure used to describe a given glyph image category.  */
-  /*                                                                       */
-  /* <Fields>                                                              */
-  /*    font       :: An @FTC_FontRec used to describe the glyph's face    */
-  /*                  and size.                                            */
-  /*                                                                       */
-  /*    image_type :: The glyph image's type.                              */
-  /*                                                                       */
-  typedef struct  FTC_Image_Desc_
+  typedef struct FTC_IFamilyClassRec_
   {
-    FTC_FontRec  font;
-    FT_UInt      image_type;
+    FTC_MruListClassRec        clazz;
+    FTC_IFamily_LoadGlyphFunc  family_load_glyph;
 
-  } FTC_Image_Desc;
+  } FTC_IFamilyClassRec;
 
+  typedef const FTC_IFamilyClassRec*  FTC_IFamilyClass;
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Type>                                                                */
-  /*    FTC_Image_Cache                                                    */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    THIS TYPE IS DEPRECATED.  Use @FTC_ImageCache instead.             */
-  /*                                                                       */
-  typedef FTC_ImageCache  FTC_Image_Cache;
-
+#define  FTC_IFAMILY_CLASS(x) ((FTC_IFamilyClass)(x))
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    FTC_Image_Cache_New                                                */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    THIS FUNCTION IS DEPRECATED.  Use @FTC_ImageCache_New instead.     */
-  /*                                                                       */
-  /*    Creates a new glyph image cache.                                   */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    manager :: The parent manager for the image cache.                 */
-  /*                                                                       */
-  /* <Output>                                                              */
-  /*    acache  :: A handle to the new glyph image cache object.           */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
-  FT_EXPORT( FT_Error )
-  FTC_Image_Cache_New( FTC_Manager       manager,
-                       FTC_Image_Cache  *acache );
+#define  FTC_CACHE__IFAMILY_CLASS(x)  \
+            FTC_IFAMILY_CLASS( FTC_CACHE__GCACHE_CLASS(x)->family_class )
 
+ /* can be used as a @FTC_Node_FreeFunc */
+  FT_EXPORT( void )
+  FTC_INode_Free( FTC_INode  inode,
+                  FTC_Cache  cache );
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    FTC_Image_Cache_Lookup                                             */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    THIS FUNCTION IS DEPRECATED.  Use @FTC_ImageCache_Lookup instead.  */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    cache  :: A handle to the source glyph image cache.                */
-  /*                                                                       */
-  /*    desc   :: A pointer to a glyph image descriptor.                   */
-  /*                                                                       */
-  /*    gindex :: The glyph index to retrieve.                             */
-  /*                                                                       */
-  /* <Output>                                                              */
-  /*    aglyph :: The corresponding @FT_Glyph object.  0 in case of        */
-  /*              failure.                                                 */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    The returned glyph is owned and managed by the glyph image cache.  */
-  /*    Never try to transform or discard it manually!  You can however    */
-  /*    create a copy with @FT_Glyph_Copy and modify the new one.          */
-  /*                                                                       */
-  /*    Because the glyph image cache limits the total amount of memory    */
-  /*    taken by the glyphs it holds, the returned glyph might disappear   */
-  /*    on a later invocation of this function!  It is a cache after       */
-  /*    all...                                                             */
-  /*                                                                       */
-  /*    Use this function to "lock" the glyph as long as it is needed.     */
-  /*                                                                       */
+ /* can be used as @FTC_Node_NewFunc. "gquery.index" & "gquery.family" must
+  * be set correctly. this function will call the 'family_load_glyph' method
+  * to load the FT_Glyph into the cache node
+  */
   FT_EXPORT( FT_Error )
-  FTC_Image_Cache_Lookup( FTC_Image_Cache  cache,
-                          FTC_Image_Desc*  desc,
-                          FT_UInt          gindex,
-                          FT_Glyph        *aglyph );
+  FTC_INode_New( FTC_INode   *pinode,
+                 FTC_GQuery   gquery,
+                 FTC_Cache    cache );
+
+ /* can be used as @FTC_Node_WeightFunc */
+  FT_EXPORT( FT_ULong )
+  FTC_INode_Weight( FTC_INode  inode );
 
  /* */
 
 FT_END_HEADER
 
-
 #endif /* __FTCIMAGE_H__ */
 
 
diff --git a/include/freetype/cache/ftcmanag.h b/include/freetype/cache/ftcmanag.h
index 97c7759..34f3857 100644
--- a/include/freetype/cache/ftcmanag.h
+++ b/include/freetype/cache/ftcmanag.h
@@ -65,7 +65,7 @@
 
 #include <ft2build.h>
 #include FT_CACHE_H
-#include FT_CACHE_INTERNAL_LRU_H
+#include FT_CACHE_INTERNAL_MRU_H
 #include FT_CACHE_INTERNAL_CACHE_H
 
 
@@ -80,99 +80,32 @@ FT_BEGIN_HEADER
   /*************************************************************************/
 
 
-#define FTC_MAX_FACES_DEFAULT  2
-#define FTC_MAX_SIZES_DEFAULT  4
-#define FTC_MAX_BYTES_DEFAULT  200000L  /* ~200kByte by default */
+#define FTC_MAX_FACES_DEFAULT    2
+#define FTC_MAX_SIZES_DEFAULT    4
+#define FTC_MAX_BYTES_DEFAULT    200000L  /* ~200kByte by default */
 
   /* maximum number of caches registered in a single manager */
 #define FTC_MAX_CACHES         16
 
-
-  typedef struct  FTC_FamilyEntryRec_
-  {
-    FTC_Family  family;
-    FTC_Cache   cache;
-    FT_UInt     index;
-    FT_UInt     link;
-
-  } FTC_FamilyEntryRec, *FTC_FamilyEntry;
-
-
-#define FTC_FAMILY_ENTRY_NONE  ( (FT_UInt)-1 )
-
-
-  typedef struct  FTC_FamilyTableRec_
-  {
-    FT_UInt          count;
-    FT_UInt          size;
-    FTC_FamilyEntry  entries;
-    FT_UInt          free;
-  
-  } FTC_FamilyTableRec, *FTC_FamilyTable;
-
-
-  FT_EXPORT( FT_Error )
-  ftc_family_table_alloc( FTC_FamilyTable   table,
-                          FT_Memory         memory,
-                          FTC_FamilyEntry  *aentry );
-
-  FT_EXPORT( void )
-  ftc_family_table_free( FTC_FamilyTable  table,
-                         FT_UInt          idx );
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Struct>                                                              */
-  /*    FTC_ManagerRec                                                     */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    The cache manager structure.                                       */
-  /*                                                                       */
-  /* <Fields>                                                              */
-  /*    library      :: A handle to a FreeType library instance.           */
-  /*                                                                       */
-  /*    faces_list   :: The lru list of @FT_Face objects in the cache.     */
-  /*                                                                       */
-  /*    sizes_list   :: The lru list of @FT_Size objects in the cache.     */
-  /*                                                                       */
-  /*    max_weight   :: The maximum cache pool weight.                     */
-  /*                                                                       */
-  /*    cur_weight   :: The current cache pool weight.                     */
-  /*                                                                       */
-  /*    num_nodes    :: The current number of nodes in the manager.        */
-  /*                                                                       */
-  /*    nodes_list   :: The global lru list of all cache nodes.            */
-  /*                                                                       */
-  /*    caches       :: A table of installed/registered cache objects.     */
-  /*                                                                       */
-  /*    request_data :: User-provided data passed to the requester.        */
-  /*                                                                       */
-  /*    request_face :: User-provided function used to implement a mapping */
-  /*                    between abstract @FTC_FaceID values and real       */
-  /*                    @FT_Face objects.                                  */
-  /*                                                                       */
-  /*    families     :: Global table of families.                          */
-  /*                                                                       */
   typedef struct  FTC_ManagerRec_
   {
     FT_Library          library;
-    FT_LruList          faces_list;
-    FT_LruList          sizes_list;
+    FT_Memory           memory;
 
+    FTC_Node            nodes_list;
     FT_ULong            max_weight;
     FT_ULong            cur_weight;
-    
     FT_UInt             num_nodes;
-    FTC_Node            nodes_list;
     
-    FTC_Cache           caches[FTC_MAX_CACHES];
+    FTC_Cache           caches[ FTC_MAX_CACHES ];
+    FT_UInt             num_caches;
+
+    FTC_MruListRec      faces;
+    FTC_MruListRec      sizes;
 
     FT_Pointer          request_data;
     FTC_Face_Requester  request_face;
 
-    FTC_FamilyTableRec  families;
-
   } FTC_ManagerRec;
 
 
@@ -201,43 +134,58 @@ FT_BEGIN_HEADER
   FTC_Manager_Compress( FTC_Manager  manager );
 
 
+ /* try to flush "count" old nodes from the cache. return the number
+  * of really flushed nodes
+  */
+  FT_EXPORT( FT_UInt )
+  FTC_Manager_FlushN( FTC_Manager  manager,
+                       FT_UInt      count );
+
+
   /* this must be used internally for the moment */
   FT_EXPORT( FT_Error )
-  FTC_Manager_Register_Cache( FTC_Manager      manager,
-                              FTC_Cache_Class  clazz,
-                              FTC_Cache       *acache );
+  FTC_Manager_RegisterCache( FTC_Manager      manager,
+                             FTC_CacheClass   clazz,
+                             FTC_Cache       *acache );
 
+ /* */
 
-  /* can be called to increment a node's reference count */
-  FT_EXPORT( void )
-  FTC_Node_Ref( FTC_Node     node,
-                FTC_Manager  manager );
+  typedef struct FTC_ScalerRec_
+  {
+    FTC_FaceID   face_id;
+    FT_UInt      width;
+    FT_UInt      height;
+    FT_Int       pixel;
+    FT_UInt      x_res;
+    FT_UInt      y_res;
+  
+  } FTC_ScalerRec, *FTC_Scaler;
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    FTC_Node_Unref                                                     */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Decrement a cache node's internal reference count.  When the count */
-  /*    reaches 0, it is not destroyed but becomes eligible for subsequent */
-  /*    cache flushes.                                                     */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    node    :: The cache node handle.                                  */
-  /*                                                                       */
-  /*    manager :: The cache manager handle.                               */
-  /*                                                                       */
-  FT_EXPORT( void )
-  FTC_Node_Unref( FTC_Node     node,
-                  FTC_Manager  manager );
+#define  FTC_SCALER_COMPARE(a,b)                  \
+    ( (a)->face_id      == (b)->face_id      &&   \
+      (a)->width        == (b)->width        &&   \
+      (a)->height       == (b)->height       &&   \
+      ((a)->pixel != 0) == ((b)->pixel != 0) &&   \
+      ( (a)->pixel ||                   \
+        ( (a)->x_res == (b)->x_res &&   \
+          (a)->y_res == (b)->y_res ) ) )
+
+#define  FTC_SCALER_HASH(q)                                  \
+    ( FTC_FACE_ID_HASH((q)->face_id) +                       \
+      (q)->width + (q)->height*7 +                           \
+      (q)->pixel ? ( (q)->x_res*33 ^ (q)->y_res*61 ) : 0 )
+
+
+  FT_EXPORT( FT_Error )
+  FTC_Manager_LookupSize( FTC_Manager    manager,
+                           FTC_Scaler     scaler,
+                           FT_Size       *asize );
 
  /* */
 
 FT_END_HEADER
 
-
 #endif /* __FTCMANAG_H__ */
 
 
diff --git a/include/freetype/cache/ftcmru.h b/include/freetype/cache/ftcmru.h
new file mode 100644
index 0000000..e0232fb
--- /dev/null
+++ b/include/freetype/cache/ftcmru.h
@@ -0,0 +1,143 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftcmru.h                                                               */
+/*                                                                         */
+/*    Simple MRU list-cache (specification).                               */
+/*                                                                         */
+/*  Copyright 2000-2001, 2003 by                                           */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* An MRU is a list that cannot hold more than a certain number of       */
+  /* elements (`max_elements').  All elements in the list are sorted in    */
+  /* least-recently-used order, i.e., the `oldest' element is at the tail  */
+  /* of the list.                                                          */
+  /*                                                                       */
+  /* When doing a lookup (either through `Lookup()' or `Lookup_Node()'),   */
+  /* the list is searched for an element with the corresponding key.  If   */
+  /* it is found, the element is moved to the head of the list and is      */
+  /* returned.                                                             */
+  /*                                                                       */
+  /* If no corresponding element is found, the lookup routine will try to  */
+  /* obtain a new element with the relevant key.  If the list is already   */
+  /* full, the oldest element from the list is discarded and replaced by a */
+  /* new one; a new element is added to the list otherwise.                */
+  /*                                                                       */
+  /* Note that it is possible to pre-allocate the element list nodes.      */
+  /* This is handy if `max_elements' is sufficiently small, as it saves    */
+  /* allocations/releases during the lookup process.                       */
+  /*                                                                       */
+  /*************************************************************************/
+
+
+#ifndef __FTCMRU_H__
+#define __FTCMRU_H__
+
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#ifdef FREETYPE_H
+#error "freetype.h of FreeType 1 has been loaded!"
+#error "Please fix the directory search order for header files"
+#error "so that freetype.h of FreeType 2 is found first."
+#endif
+
+
+FT_BEGIN_HEADER
+
+  typedef struct FTC_MruListRec_*              FTC_MruList;
+
+  typedef struct FTC_MruNodeRec_*              FTC_MruNode;
+
+  typedef struct FTC_MruListClassRec_ const *  FTC_MruListClass;
+
+  typedef struct FTC_MruNodeRec_
+  {
+    FTC_MruNode   next;
+
+  } FTC_MruNodeRec;
+
+  typedef FT_Int       (*FTC_MruNode_CompareFunc)( FTC_MruNode  node,
+                                                   FT_Pointer   key );
+
+  typedef FT_Error     (*FTC_MruNode_InitFunc)( FTC_MruNode  node,
+                                                FT_Pointer    key,
+                                                FT_Pointer    data );
+
+  typedef FT_Error     (*FTC_MruNode_ResetFunc)( FTC_MruNode  node,
+                                                 FT_Pointer   key,
+                                                 FT_Pointer   data );
+
+  typedef void         (*FTC_MruNode_DoneFunc)( FTC_MruNode  node,
+                                                FT_Pointer   data );
+
+  typedef struct FTC_MruListClassRec_
+  {
+    FT_UInt                   node_size;
+    FTC_MruNode_CompareFunc   node_compare;
+    FTC_MruNode_InitFunc      node_init;
+    FTC_MruNode_ResetFunc     node_reset;
+    FTC_MruNode_DoneFunc      node_done;
+
+  } FTC_MruListClassRec;
+
+  typedef struct FTC_MruListRec_
+  {
+    FT_UInt                  num_nodes;
+    FT_UInt                  max_nodes;
+    FTC_MruNode              nodes;
+    FT_Pointer               data;
+    FTC_MruListClassRec      clazz;
+    FT_Memory                memory;
+
+  } FTC_MruListRec;
+
+
+  FT_EXPORT( void )
+  FTC_MruList_Init( FTC_MruList       list,
+                    FTC_MruListClass  clazz,
+                    FT_UInt           max_nodes,
+                    FT_Pointer        data,
+                    FT_Memory         memory );
+
+  FT_EXPORT( void )
+  FTC_MruList_Reset( FTC_MruList  list );
+
+
+  FT_EXPORT( void )
+  FTC_MruList_Done( FTC_MruList  list );
+
+
+  FT_EXPORT( FT_Error )
+  FTC_MruList_Lookup( FTC_MruList   list,
+                      FT_Pointer    key,
+                      FTC_MruNode  *pnode );
+
+  FT_EXPORT( void )
+  FTC_MruList_Remove( FTC_MruList   list,
+                      FTC_MruNode   node );
+
+  FT_EXPORT( void )
+  FTC_MruList_RemoveSelection( FTC_MruList              list,
+                               FTC_MruNode_CompareFunc  select,
+                               FT_Pointer               key );
+ /* */
+
+FT_END_HEADER
+
+
+#endif /* __FTCMRU_H__ */
+
+
+/* END */
diff --git a/include/freetype/cache/ftcsbits.h b/include/freetype/cache/ftcsbits.h
index 6f8ef99..e79543a 100644
--- a/include/freetype/cache/ftcsbits.h
+++ b/include/freetype/cache/ftcsbits.h
@@ -22,251 +22,69 @@
 
 #include <ft2build.h>
 #include FT_CACHE_H
-#include FT_CACHE_IMAGE_H
+#include FT_CACHE_INTERNAL_GLYPH_H
 
 
 FT_BEGIN_HEADER
 
+#define FTC_SBIT_ITEMS_PER_NODE  16
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Section>                                                             */
-  /*    cache_subsystem                                                    */
-  /*                                                                       */
-  /*************************************************************************/
-
+  typedef struct  FTC_SNodeRec_
+  {
+    FTC_GNodeRec  gnode;
+    FT_UInt       count;
+    FTC_SBitRec   sbits[ FTC_SBIT_ITEMS_PER_NODE ];
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Type>                                                                */
-  /*    FTC_SBit                                                           */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    A handle to a small bitmap descriptor.  See the @FTC_SBitRec       */
-  /*    structure for details.                                             */
-  /*                                                                       */
-  typedef struct FTC_SBitRec_*  FTC_SBit;
+  } FTC_SNodeRec, *FTC_SNode;
 
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Struct>                                                              */
-  /*    FTC_SBitRec                                                        */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    A very compact structure used to describe a small glyph bitmap.    */
-  /*                                                                       */
-  /* <Fields>                                                              */
-  /*    width     :: The bitmap width in pixels.                           */
-  /*                                                                       */
-  /*    height    :: The bitmap height in pixels.                          */
-  /*                                                                       */
-  /*    left      :: The horizontal distance from the pen position to the  */
-  /*                 left bitmap border (a.k.a. `left side bearing', or    */
-  /*                 `lsb').                                               */
-  /*                                                                       */
-  /*    top       :: The vertical distance from the pen position (on the   */
-  /*                 baseline) to the upper bitmap border (a.k.a. `top     */
-  /*                 side bearing').  The distance is positive for upwards */
-  /*                 Y coordinates.                                        */
-  /*                                                                       */
-  /*    format    :: The format of the glyph bitmap (monochrome or gray).  */
-  /*                                                                       */
-  /*    max_grays :: Maximum gray level value (in the range 1 to 255).     */
-  /*                                                                       */
-  /*    pitch     :: The number of bytes per bitmap line.  May be positive */
-  /*                 or negative.                                          */
-  /*                                                                       */
-  /*    xadvance  :: The horizontal advance width in pixels.               */
-  /*                                                                       */
-  /*    yadvance  :: The vertical advance height in pixels.                */
-  /*                                                                       */
-  /*    buffer   :: A pointer to the bitmap pixels.                        */
-  /*                                                                       */
-  typedef struct  FTC_SBitRec_
-  {
-    FT_Byte   width;
-    FT_Byte   height;
-    FT_Char   left;
-    FT_Char   top;
+#define FTC_SNODE( x )  ( (FTC_SNode)( x ) )
+#define FTC_SNODE_GINDEX( x )  FTC_GNODE(x)->gindex
+#define FTC_SNODE_FAMILY( x )  FTC_GNODE(x)->family
 
-    FT_Byte   format;
-    FT_Byte   max_grays;
-    FT_Short  pitch;
-    FT_Char   xadvance;
-    FT_Char   yadvance;
+  typedef FT_UInt   (*FTC_SFamily_GetCountFunc)( FTC_Family   family,
+                                                 FTC_Manager  manager );
 
-    FT_Byte*  buffer;
+  typedef FT_Error  (*FTC_SFamily_LoadGlyphFunc)( FTC_Family   family,
+                                                  FT_UInt      gindex,
+                                                  FTC_Manager  manager,
+                                                  FT_Face     *aface );
 
-  } FTC_SBitRec;
+  typedef struct FTC_SFamilyClassRec_
+  {
+    FTC_MruListClassRec        clazz;
+    FTC_SFamily_GetCountFunc   family_get_count;
+    FTC_SFamily_LoadGlyphFunc  family_load_glyph;
 
+  } FTC_SFamilyClassRec;
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Type>                                                                */
-  /*    FTC_SBitCache                                                      */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    A handle to a small bitmap cache.  These are special cache objects */
-  /*    used to store small glyph bitmaps (and anti-aliased pixmaps) in a  */
-  /*    much more efficient way than the traditional glyph image cache     */
-  /*    implemented by @FTC_ImageCache.                                    */
-  /*                                                                       */
-  typedef struct FTC_SBitCacheRec_*  FTC_SBitCache;
+  typedef const FTC_SFamilyClassRec*  FTC_SFamilyClass;
 
+#define  FTC_SFAMILY_CLASS(x)  ((FTC_SFamilyClass)(x))
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Type>                                                                */
-  /*    FTC_SBit_Cache                                                     */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    DEPRECATED.  Use @FTC_SBitCache instead.                           */
-  /*                                                                       */
-  typedef FTC_SBitCache  FTC_SBit_Cache;
+#define  FTC_CACHE__SFAMILY_CLASS(x)  \
+             FTC_SFAMILY_CLASS( FTC_CACHE__GCACHE_CLASS(x)->family_class )
 
+  FT_EXPORT( void )
+  FTC_SNode_Free( FTC_SNode  snode,
+                  FTC_Cache  cache );
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    FTC_SBitCache_New                                                  */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Creates a new cache to store small glyph bitmaps.                  */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    manager :: A handle to the source cache manager.                   */
-  /*                                                                       */
-  /* <Output>                                                              */
-  /*    acache  :: A handle to the new sbit cache.  NULL in case of error. */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
   FT_EXPORT( FT_Error )
-  FTC_SBitCache_New( FTC_Manager     manager,
-                     FTC_SBitCache  *acache );
+  FTC_SNode_New( FTC_SNode   *psnode,
+                 FTC_GQuery   gquery,
+                 FTC_Cache    cache );
 
+  FT_EXPORT( FT_ULong )
+  FTC_SNode_Weight( FTC_SNode  inode );
 
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    FTC_SBitCache_Lookup                                               */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    Looks up a given small glyph bitmap in a given sbit cache and      */
-  /*    "lock" it to prevent its flushing from the cache until needed      */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    cache  :: A handle to the source sbit cache.                       */
-  /*                                                                       */
-  /*    type   :: A pointer to the glyph image type descriptor.            */
-  /*                                                                       */
-  /*    gindex :: The glyph index.                                         */
-  /*                                                                       */
-  /* <Output>                                                              */
-  /*    sbit   :: A handle to a small bitmap descriptor.                   */
-  /*                                                                       */
-  /*    anode  :: Used to return the address of of the corresponding cache */
-  /*              node after incrementing its reference count (see note    */
-  /*              below).                                                  */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    The small bitmap descriptor and its bit buffer are owned by the    */
-  /*    cache and should never be freed by the application.  They might    */
-  /*    as well disappear from memory on the next cache lookup, so don't   */
-  /*    treat them as persistent data.                                     */
-  /*                                                                       */
-  /*    The descriptor's `buffer' field is set to 0 to indicate a missing  */
-  /*    glyph bitmap.                                                      */
-  /*                                                                       */
-  /*    If "anode" is _not_ NULL, it receives the address of the cache     */
-  /*    node containing the bitmap, after increasing its reference count.  */
-  /*    This ensures that the node (as well as the image) will always be   */
-  /*    kept in the cache until you call @FTC_Node_Unref to "release" it.  */
-  /*                                                                       */
-  /*    If "anode" is NULL, the cache node is left unchanged, which means  */
-  /*    that the bitmap could be flushed out of the cache on the next      */
-  /*    call to one of the caching sub-system APIs.  Don't assume that it  */
-  /*    is persistent!                                                     */
-  /*                                                                       */
-  FT_EXPORT( FT_Error )
-  FTC_SBitCache_Lookup( FTC_SBitCache    cache,
-                        FTC_ImageType    type,
-                        FT_UInt          gindex,
-                        FTC_SBit        *sbit,
-                        FTC_Node        *anode );
 
+  FT_EXPORT( FT_Bool )
+  FTC_SNode_Compare( FTC_SNode   snode,
+                     FTC_GQuery  gquery,
+                     FTC_Cache   cache );
 
   /* */
 
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    FTC_SBit_Cache_New                                                 */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    DEPRECATED.  Use @FTC_SBitCache_New instead.                       */
-  /*                                                                       */
-  /*    Creates a new cache to store small glyph bitmaps.                  */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    manager :: A handle to the source cache manager.                   */
-  /*                                                                       */
-  /* <Output>                                                              */
-  /*    acache  :: A handle to the new sbit cache.  NULL in case of error. */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
-  FT_EXPORT( FT_Error )
-  FTC_SBit_Cache_New( FTC_Manager      manager,
-                      FTC_SBit_Cache  *acache );
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* <Function>                                                            */
-  /*    FTC_SBit_Cache_Lookup                                              */
-  /*                                                                       */
-  /* <Description>                                                         */
-  /*    DEPRECATED.  Use @FTC_SBitCache_Lookup instead.                    */
-  /*                                                                       */
-  /*    Looks up a given small glyph bitmap in a given sbit cache.         */
-  /*                                                                       */
-  /* <Input>                                                               */
-  /*    cache  :: A handle to the source sbit cache.                       */
-  /*                                                                       */
-  /*    desc   :: A pointer to the glyph image descriptor.                 */
-  /*                                                                       */
-  /*    gindex :: The glyph index.                                         */
-  /*                                                                       */
-  /* <Output>                                                              */
-  /*    sbit   :: A handle to a small bitmap descriptor.                   */
-  /*                                                                       */
-  /* <Return>                                                              */
-  /*    FreeType error code.  0 means success.                             */
-  /*                                                                       */
-  /* <Note>                                                                */
-  /*    The small bitmap descriptor and its bit buffer are owned by the    */
-  /*    cache and should never be freed by the application.  They might    */
-  /*    as well disappear from memory on the next cache lookup, so don't   */
-  /*    treat them as persistent data.                                     */
-  /*                                                                       */
-  /*    The descriptor's `buffer' field is set to 0 to indicate a missing  */
-  /*    glyph bitmap.                                                      */
-  /*                                                                       */
-  FT_EXPORT( FT_Error )
-  FTC_SBit_Cache_Lookup( FTC_SBit_Cache   cache,
-                         FTC_Image_Desc*  desc,
-                         FT_UInt          gindex,
-                         FTC_SBit        *sbit );
-
-
 FT_END_HEADER
 
 #endif /* __FTCSBITS_H__ */
diff --git a/include/freetype/cache/ftlru.h b/include/freetype/cache/ftlru.h
deleted file mode 100644
index d446c60..0000000
--- a/include/freetype/cache/ftlru.h
+++ /dev/null
@@ -1,208 +0,0 @@
-/***************************************************************************/
-/*                                                                         */
-/*  ftlru.h                                                                */
-/*                                                                         */
-/*    Simple LRU list-cache (specification).                               */
-/*                                                                         */
-/*  Copyright 2000-2001, 2003 by                                           */
-/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
-/*                                                                         */
-/*  This file is part of the FreeType project, and may only be used,       */
-/*  modified, and distributed under the terms of the FreeType project      */
-/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
-/*  this file you indicate that you have read the license and              */
-/*  understand and accept it fully.                                        */
-/*                                                                         */
-/***************************************************************************/
-
-
-  /*************************************************************************/
-  /*                                                                       */
-  /* An LRU is a list that cannot hold more than a certain number of       */
-  /* elements (`max_elements').  All elements in the list are sorted in    */
-  /* least-recently-used order, i.e., the `oldest' element is at the tail  */
-  /* of the list.                                                          */
-  /*                                                                       */
-  /* When doing a lookup (either through `Lookup()' or `Lookup_Node()'),   */
-  /* the list is searched for an element with the corresponding key.  If   */
-  /* it is found, the element is moved to the head of the list and is      */
-  /* returned.                                                             */
-  /*                                                                       */
-  /* If no corresponding element is found, the lookup routine will try to  */
-  /* obtain a new element with the relevant key.  If the list is already   */
-  /* full, the oldest element from the list is discarded and replaced by a */
-  /* new one; a new element is added to the list otherwise.                */
-  /*                                                                       */
-  /* Note that it is possible to pre-allocate the element list nodes.      */
-  /* This is handy if `max_elements' is sufficiently small, as it saves    */
-  /* allocations/releases during the lookup process.                       */
-  /*                                                                       */
-  /*************************************************************************/
-
-
-  /*************************************************************************/
-  /*************************************************************************/
-  /*************************************************************************/
-  /*************************************************************************/
-  /*************************************************************************/
-  /*********                                                       *********/
-  /*********             WARNING, THIS IS BETA CODE.               *********/
-  /*********                                                       *********/
-  /*************************************************************************/
-  /*************************************************************************/
-  /*************************************************************************/
-  /*************************************************************************/
-  /*************************************************************************/
-
-
-#ifndef __FTLRU_H__
-#define __FTLRU_H__
-
-
-#include <ft2build.h>
-#include FT_FREETYPE_H
-
-#ifdef FREETYPE_H
-#error "freetype.h of FreeType 1 has been loaded!"
-#error "Please fix the directory search order for header files"
-#error "so that freetype.h of FreeType 2 is found first."
-#endif
-
-
-FT_BEGIN_HEADER
-
-
-  /* generic list key type */
-  typedef FT_Pointer  FT_LruKey;
-
-  /* a list list handle */
-  typedef struct FT_LruListRec_*  FT_LruList;
-
-  /* a list class handle */
-  typedef const struct FT_LruList_ClassRec_*  FT_LruList_Class;
-
-  /* a list node handle */
-  typedef struct FT_LruNodeRec_*  FT_LruNode;
-
-  /* the list node structure */
-  typedef struct  FT_LruNodeRec_
-  {
-    FT_LruNode  next;
-    FT_LruKey   key;
-
-  } FT_LruNodeRec;
-
-
-  /* the list structure */
-  typedef struct  FT_LruListRec_
-  {
-    FT_Memory         memory;
-    FT_LruList_Class  clazz;
-    FT_LruNode        nodes;
-    FT_UInt           max_nodes;
-    FT_UInt           num_nodes;
-    FT_Pointer        data;
-
-  } FT_LruListRec;
-
-
-  /* initialize a list list */
-  typedef FT_Error
-  (*FT_LruList_InitFunc)( FT_LruList  list );
-
-  /* finalize a list list */
-  typedef void
-  (*FT_LruList_DoneFunc)( FT_LruList  list );
-
-  /* this method is used to initialize a new list element node */
-  typedef FT_Error
-  (*FT_LruNode_InitFunc)( FT_LruNode  node,
-                          FT_LruKey   key,
-                          FT_Pointer  data );
-
-  /* this method is used to finalize a given list element node */
-  typedef void
-  (*FT_LruNode_DoneFunc)( FT_LruNode  node,
-                          FT_Pointer  data );
-
-  /* If defined, this method is called when the list if full        */
-  /* during the lookup process -- it is used to change the contents */
-  /* of a list element node instead of calling `done_element()',    */
-  /* then `init_element()'.  Set it to 0 for default behaviour.     */
-  typedef FT_Error
-  (*FT_LruNode_FlushFunc)( FT_LruNode  node,
-                           FT_LruKey   new_key,
-                           FT_Pointer  data );
-
-  /* If defined, this method is used to compare a list element node */
-  /* with a given key during a lookup.  If set to 0, the `key'      */
-  /* fields will be directly compared instead.                      */
-  typedef FT_Bool
-  (*FT_LruNode_CompareFunc)( FT_LruNode  node,
-                             FT_LruKey   key,
-                             FT_Pointer  data );
-
-  /* A selector is used to indicate whether a given list element node */
-  /* is part of a selection for FT_LruList_Remove_Selection().  The   */
-  /* functrion must return true (i.e., non-null) to indicate that the */
-  /* node is part of it.                                              */
-  typedef FT_Bool
-  (*FT_LruNode_SelectFunc)( FT_LruNode  node,
-                            FT_Pointer  data,
-                            FT_Pointer  list_data );
-
-  /* LRU class */
-  typedef struct  FT_LruList_ClassRec_
-  {
-    FT_UInt                 list_size;
-    FT_LruList_InitFunc     list_init;      /* optional */
-    FT_LruList_DoneFunc     list_done;      /* optional */
-
-    FT_UInt                 node_size;
-    FT_LruNode_InitFunc     node_init;     /* MANDATORY */
-    FT_LruNode_DoneFunc     node_done;     /* optional  */
-    FT_LruNode_FlushFunc    node_flush;    /* optional  */
-    FT_LruNode_CompareFunc  node_compare;  /* optional  */
-
-  } FT_LruList_ClassRec;
-
-
-  /* The following functions must be exported in the case where */
-  /* applications would want to write their own cache classes.  */
-
-  FT_EXPORT( FT_Error )
-  FT_LruList_New( FT_LruList_Class  clazz,
-                  FT_UInt           max_elements,
-                  FT_Pointer        user_data,
-                  FT_Memory         memory,
-                  FT_LruList       *alist );
-
-  FT_EXPORT( void )
-  FT_LruList_Reset( FT_LruList  list );
-
-  FT_EXPORT( void )
-  FT_LruList_Destroy ( FT_LruList  list );
-
-  FT_EXPORT( FT_Error )
-  FT_LruList_Lookup( FT_LruList  list,
-                     FT_LruKey   key,
-                     FT_LruNode *anode );
-
-  FT_EXPORT( void )
-  FT_LruList_Remove( FT_LruList  list,
-                     FT_LruNode  node );
-
-  FT_EXPORT( void )
-  FT_LruList_Remove_Selection( FT_LruList             list,
-                               FT_LruNode_SelectFunc  select_func,
-                               FT_Pointer             select_data );
-
- /* */
-
-FT_END_HEADER
-
-
-#endif /* __FTLRU_H__ */
-
-
-/* END */
diff --git a/include/freetype/config/ftheader.h b/include/freetype/config/ftheader.h
index 22cd62e..da20a33 100644
--- a/include/freetype/config/ftheader.h
+++ b/include/freetype/config/ftheader.h
@@ -433,7 +433,10 @@
   /*    see the API defined in @FT_CACHE_SMALL_BITMAPS_H if you only need  */
   /*    to store small glyph bitmaps, as it will use less memory.          */
   /*                                                                       */
-#define FT_CACHE_IMAGE_H  <freetype/cache/ftcimage.h>
+  /*    this macro is *DEPRECATED*, simply include @FT_CACHE_H and you'll  */
+  /*    have all glyph image-related cache declarations                    */
+  /*                                                                       */
+#define FT_CACHE_IMAGE_H    FT_CACHE_H
 
 
   /*************************************************************************/
@@ -450,7 +453,10 @@
   /*    in @FT_CACHE_IMAGE_H if you want to cache arbitrary glyph images,  */
   /*    including scalable outlines.                                       */
   /*                                                                       */
-#define FT_CACHE_SMALL_BITMAPS_H  <freetype/cache/ftcsbits.h>
+  /*    this macro is *DEPRECATED*, simply include @FT_CACHE_H and you'll  */
+  /*    have all small bitmaps-related cache declarations                  */
+  /*                                                                       */
+#define FT_CACHE_SMALL_BITMAPS_H  FT_CACHE_H
 
 
   /*************************************************************************/
@@ -462,7 +468,10 @@
   /*    A macro used in #include statements to name the file containing    */
   /*    the `charmap' API of the FreeType 2 cache sub-system.              */
   /*                                                                       */
-#define FT_CACHE_CHARMAP_H  <freetype/cache/ftccmap.h>
+  /*    this macro is *DEPRECATED*, simply include @FT_CACHE_H and you'll  */
+  /*    have all charmap-based cache declarations                          */
+  /*                                                                       */
+#define FT_CACHE_CHARMAP_H     FT_CACHE_H
 
 
   /*************************************************************************/
@@ -515,9 +524,13 @@
 
 #define FT_CACHE_MANAGER_H         <freetype/cache/ftcmanag.h>
 
-#define FT_CACHE_INTERNAL_LRU_H    <freetype/cache/ftlru.h>
-#define FT_CACHE_INTERNAL_GLYPH_H  <freetype/cache/ftcglyph.h>
+#define FT_CACHE_INTERNAL_MRU_H      <freetype/cache/ftcmru.h>
+#define FT_CACHE_INTERNAL_MANAGER_H  <freetype/cache/ftcmanag.h>
 #define FT_CACHE_INTERNAL_CACHE_H  <freetype/cache/ftccache.h>
+#define FT_CACHE_INTERNAL_GLYPH_H    <freetype/cache/ftcglyph.h>
+#define FT_CACHE_INTERNAL_IMAGE_H    <freetype/cache/ftcimage.h>
+#define FT_CACHE_INTERNAL_SBITS_H    <freetype/cache/ftcsbits.h>
+
 
 #define FT_XFREE86_H               <freetype/ftxf86.h>
 
diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h
index 3581caa..428234e 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -277,8 +277,8 @@ FT_BEGIN_HEADER
   /*   Do not #undef these macros here since the build system might define */
   /*   them for certain configurations only.                               */
   /*                                                                       */
-/* #define FT_DEBUG_LEVEL_ERROR */
-/* #define FT_DEBUG_LEVEL_TRACE */
+#define FT_DEBUG_LEVEL_ERROR
+#define FT_DEBUG_LEVEL_TRACE
 
 
   /*************************************************************************/
@@ -296,7 +296,7 @@ FT_BEGIN_HEADER
   /*   Do not #undef this macro here since the build system might define   */
   /*   it for certain configurations only.                                 */
   /*                                                                       */
-/* #define FT_DEBUG_MEMORY */
+#define FT_DEBUG_MEMORY
 
 
   /*************************************************************************/
diff --git a/include/freetype/ftcache.h b/include/freetype/ftcache.h
index 65bd210..10178c1 100644
--- a/include/freetype/ftcache.h
+++ b/include/freetype/ftcache.h
@@ -63,7 +63,7 @@ FT_BEGIN_HEADER
   /*   FTC_Face_Requester                                                  */
   /*                                                                       */
   /*   FTC_Manager_New                                                     */
-  /*   FTC_Manager_Lookup_Face                                             */
+  /*   FTC_Manager_LookupFace                                             */
   /*   FTC_Manager_Lookup_Size                                             */
   /*                                                                       */
   /*   FTC_Node                                                            */
@@ -257,28 +257,16 @@ FT_BEGIN_HEADER
   /*    Creates a new cache manager.                                       */
   /*                                                                       */
   /* <Input>                                                               */
-  /*    library   :: The parent FreeType library handle to use.            */
+  /*    library     :: The parent FreeType library handle to use.          */
   /*                                                                       */
-  /*    max_faces :: Maximum number of faces to keep alive in manager.     */
-  /*                 Use 0 for defaults (currently 2; see the value of     */
-  /*                 FTC_MAX_FACES_DEFAULT in                              */
-  /*                 `include/freetype/cache/ftcmanag.h').                 */
+  /*    max_bytes   :: Maximum number of bytes to use for cached data.     */
+  /*                   Use 0 for defaults.                                 */
   /*                                                                       */
-  /*    max_sizes :: Maximum number of sizes to keep alive in manager.     */
-  /*                 Use 0 for defaults (currently 4; see the value of     */
-  /*                 FTC_MAX_SIZES_DEFAULT in                              */
-  /*                 `include/freetype/cache/ftcmanag.h').                 */
+  /*    requester   :: An application-provided callback used to translate  */
+  /*                   face IDs into real @FT_Face objects.                */
   /*                                                                       */
-  /*    max_bytes :: Maximum number of bytes to use for cached data.       */
-  /*                 Use 0 for defaults (currently 200000; see the value   */
-  /*                 of FTC_MAX_BYTES_DEFAULT in                           */
-  /*                 `include/freetype/cache/ftcmanag.h').                 */
-  /*                                                                       */
-  /*    requester :: An application-provided callback used to translate    */
-  /*                 face IDs into real @FT_Face objects.                  */
-  /*                                                                       */
-  /*    req_data  :: A generic pointer that is passed to the requester     */
-  /*                 each time it is called (see @FTC_Face_Requester).     */
+  /*    req_data    :: A generic pointer that is passed to the requester   */
+  /*                   each time it is called (see @FTC_Face_Requester).   */
   /*                                                                       */
   /* <Output>                                                              */
   /*    amanager  :: A handle to a new manager object.  0 in case of       */
@@ -331,7 +319,7 @@ FT_BEGIN_HEADER
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    FTC_Manager_Lookup_Face                                            */
+  /*    FTC_Manager_LookupFace                                            */
   /*                                                                       */
   /* <Description>                                                         */
   /*    Retrieves the @FT_Face object that corresponds to a given face ID  */
@@ -361,7 +349,7 @@ FT_BEGIN_HEADER
   /*    to transform glyphs, do it yourself after glyph loading.           */
   /*                                                                       */
   FT_EXPORT( FT_Error )
-  FTC_Manager_Lookup_Face( FTC_Manager  manager,
+  FTC_Manager_LookupFace( FTC_Manager  manager,
                            FTC_FaceID   face_id,
                            FT_Face     *aface );
 
@@ -369,48 +357,411 @@ FT_BEGIN_HEADER
   /*************************************************************************/
   /*                                                                       */
   /* <Function>                                                            */
-  /*    FTC_Manager_Lookup_Size                                            */
+  /*    FTC_Node_Unref                                                     */
   /*                                                                       */
   /* <Description>                                                         */
-  /*    Retrieves the @FT_Face and @FT_Size objects that correspond to a   */
-  /*    given font.                                                        */
+  /*    Decrement a cache node's internal reference count.  When the count */
+  /*    reaches 0, it is not destroyed but becomes eligible for subsequent */
+  /*    cache flushes.                                                     */
   /*                                                                       */
   /* <Input>                                                               */
+  /*    node    :: The cache node handle.                                  */
+  /*                                                                       */
+  /*    manager :: The cache manager handle.                               */
+  /*                                                                       */
+  FT_EXPORT( void )
+  FTC_Node_Unref( FTC_Node     node,
+                  FTC_Manager  manager );
+
+
+ /* remove all nodes belonging to a given face_id */
+  FT_EXPORT( void )
+  FTC_Manager_RemoveFaceID( FTC_Manager  manager,
+                             FTC_FaceID   face_id );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Section>                                                             */
+  /*    cache_subsystem                                                    */
+  /*                                                                       */
+  /*************************************************************************/
+
+  /************************************************************************
+   *
+   * @type:
+   *    FTC_CMapCache
+   *
+   * @description:
+   *    An opaque handle used to manager a charmap cache.  This cache is
+   *    to hold character codes -> glyph indices mappings.
+   */
+  typedef struct FTC_CMapCacheRec_*  FTC_CMapCache;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* @type:                                                                */
+  /*    FTC_CMapDesc                                                       */
+  /*                                                                       */
+  /* @description:                                                         */
+  /*    A handle to an @FTC_CMapDescRec structure used to describe a given */
+  /*    charmap in a charmap cache.                                        */
+  /*                                                                       */
+  /*    Each @FTC_CMapDesc describes which charmap (of which @FTC_FaceID)  */
+  /*    we want to use in @FTC_CMapCache_Lookup.                           */
+  /*                                                                       */
+  typedef struct FTC_CMapDescRec_*  FTC_CMapDesc;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* @function:                                                            */
+  /*    FTC_CMapCache_New                                                  */
+  /*                                                                       */
+  /* @description:                                                         */
+  /*    Creates a new charmap cache.                                       */
+  /*                                                                       */
+  /* @input:                                                               */
   /*    manager :: A handle to the cache manager.                          */
   /*                                                                       */
-  /*    font    :: The font to use.                                        */
+  /* @output:                                                              */
+  /*    acache  :: A new cache handle.  NULL in case of error.             */
+  /*                                                                       */
+  /* @return:                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  /* @note:                                                                */
+  /*    Like all other caches, this one will be destroyed with the cache   */
+  /*    manager.                                                           */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FTC_CMapCache_New( FTC_Manager     manager,
+                     FTC_CMapCache  *acache );
+
+
+ /* retrieve the index of a given charmap
+  */
+  FT_EXPORT( FT_UInt )
+  FT_Get_CharMap_Index( FT_CharMap  charmap );
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* @function:                                                            */
+  /*    FTC_CMapCache_Lookup                                               */
+  /*                                                                       */
+  /* @description:                                                         */
+  /*    Translates a character code into a glyph index, using the charmap  */
+  /*    cache.                                                             */
+  /*                                                                       */
+  /* @input:                                                               */
+  /*    cache     :: A charmap cache handle.                               */
+  /*                                                                       */
+  /*    cmap_desc :: A charmap descriptor handle.                          */
+  /*                                                                       */
+  /*    char_code :: The character code (in the corresponding charmap).    */
+  /*                                                                       */
+  /* @return:                                                              */
+  /*    Glyph index.  0 means "no glyph".                                  */
+  /*                                                                       */
+  /* @note:                                                                */
+  /*    This function doesn't return @FTC_Node handles, since there is no  */
+  /*    real use for them with typical uses of charmaps.                   */
+  /*                                                                       */
+  FT_EXPORT( FT_UInt )
+  FTC_CMapCache_Lookup( FTC_CMapCache  cache,
+                        FTC_FaceID     face_id,
+                        FT_UInt        cmap_index,
+                        FT_UInt32      char_code );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Section>                                                             */
+  /*    cache_subsystem                                                    */
+  /*                                                                       */
+  /*************************************************************************/
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                       IMAGE CACHE OBJECT                      *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
+  /*************************************************************************/
+
+  typedef struct  FTC_ImageTypeRec_
+  {
+    FTC_FaceID   face_id;
+    FT_Int       width;
+    FT_Int       height;
+    FT_Int32     flags;
+
+  } FTC_ImageTypeRec;
+
+  typedef struct FTC_ImageTypeRec_*   FTC_ImageType;
+
+ /* */
+
+#define FTC_IMAGE_TYPE_COMPARE( d1, d2 )                    \
+          ( FTC_FONT_COMPARE( &(d1)->font, &(d2)->font ) && \
+            (d1)->flags == (d2)->flags                   )
+
+#define FTC_IMAGE_TYPE_HASH( d )                    \
+          (FT_UFast)( FTC_FONT_HASH( &(d)->font ) ^ \
+                      ( (d)->flags << 4 )         )
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Type>                                                                */
+  /*    FTC_ImageCache                                                     */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    A handle to an glyph image cache object.  They are designed to     */
+  /*    hold many distinct glyph images while not exceeding a certain      */
+  /*    memory threshold.                                                  */
+  /*                                                                       */
+  typedef struct FTC_ImageCacheRec_*  FTC_ImageCache;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FTC_ImageCache_New                                                 */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Creates a new glyph image cache.                                   */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    manager :: The parent manager for the image cache.                 */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    acache  :: A handle to the new glyph image cache object.           */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FTC_ImageCache_New( FTC_Manager      manager,
+                      FTC_ImageCache  *acache );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FTC_ImageCache_Lookup                                              */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Retrieves a given glyph image from a glyph image cache.            */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    cache  :: A handle to the source glyph image cache.                */
+  /*                                                                       */
+  /*    type   :: A pointer to a glyph image type descriptor.              */
+  /*                                                                       */
+  /*    gindex :: The glyph index to retrieve.                             */
   /*                                                                       */
   /* <Output>                                                              */
-  /*    aface   :: A pointer to the handle of the face object.  Set it to  */
-  /*               zero if you don't need it.                              */
+  /*    aglyph :: The corresponding @FT_Glyph object.  0 in case of        */
+  /*              failure.                                                 */
   /*                                                                       */
-  /*    asize   :: A pointer to the handle of the size object.  Set it to  */
-  /*               zero if you don't need it.                              */
+  /*    anode  :: Used to return the address of of the corresponding cache */
+  /*              node after incrementing its reference count (see note    */
+  /*              below).                                                  */
   /*                                                                       */
   /* <Return>                                                              */
   /*    FreeType error code.  0 means success.                             */
   /*                                                                       */
   /* <Note>                                                                */
-  /*    The returned @FT_Face object is always owned by the manager.  You  */
-  /*    should never try to discard it yourself.                           */
+  /*    The returned glyph is owned and managed by the glyph image cache.  */
+  /*    Never try to transform or discard it manually!  You can however    */
+  /*    create a copy with @FT_Glyph_Copy and modify the new one.          */
   /*                                                                       */
-  /*    Never change the face's transformation matrix (i.e., never call    */
-  /*    the @FT_Set_Transform function) on a returned face!  If you need   */
-  /*    to transform glyphs, do it yourself after glyph loading.           */
+  /*    If "anode" is _not_ NULL, it receives the address of the cache     */
+  /*    node containing the glyph image, after increasing its reference    */
+  /*    count.  This ensures that the node (as well as the FT_Glyph) will  */
+  /*    always be kept in the cache until you call @FTC_Node_Unref to      */
+  /*    "release" it.                                                      */
+  /*                                                                       */
+  /*    If "anode" is NULL, the cache node is left unchanged, which means  */
+  /*    that the FT_Glyph could be flushed out of the cache on the next    */
+  /*    call to one of the caching sub-system APIs.  Don't assume that it  */
+  /*    is persistent!                                                     */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FTC_ImageCache_Lookup( FTC_ImageCache  cache,
+                         FTC_ImageType   type,
+                         FT_UInt         gindex,
+                         FT_Glyph       *aglyph,
+                         FTC_Node       *anode );
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Section>                                                             */
+  /*    cache_subsystem                                                    */
+  /*                                                                       */
+  /*************************************************************************/
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Type>                                                                */
+  /*    FTC_SBit                                                           */
   /*                                                                       */
-  /*    Similarly, the returned @FT_Size object is always owned by the     */
-  /*    manager.  You should never try to discard it, and never change its */
-  /*    settings with @FT_Set_Pixel_Sizes or @FT_Set_Char_Size!            */
+  /* <Description>                                                         */
+  /*    A handle to a small bitmap descriptor.  See the @FTC_SBitRec       */
+  /*    structure for details.                                             */
   /*                                                                       */
-  /*    The returned size object is the face's current size, which means   */
-  /*    that you can call @FT_Load_Glyph with the face if you need to.     */
+  typedef struct FTC_SBitRec_*  FTC_SBit;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Struct>                                                              */
+  /*    FTC_SBitRec                                                        */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    A very compact structure used to describe a small glyph bitmap.    */
+  /*                                                                       */
+  /* <Fields>                                                              */
+  /*    width     :: The bitmap width in pixels.                           */
+  /*                                                                       */
+  /*    height    :: The bitmap height in pixels.                          */
+  /*                                                                       */
+  /*    left      :: The horizontal distance from the pen position to the  */
+  /*                 left bitmap border (a.k.a. `left side bearing', or    */
+  /*                 `lsb').                                               */
+  /*                                                                       */
+  /*    top       :: The vertical distance from the pen position (on the   */
+  /*                 baseline) to the upper bitmap border (a.k.a. `top     */
+  /*                 side bearing').  The distance is positive for upwards */
+  /*                 Y coordinates.                                        */
+  /*                                                                       */
+  /*    format    :: The format of the glyph bitmap (monochrome or gray).  */
+  /*                                                                       */
+  /*    max_grays :: Maximum gray level value (in the range 1 to 255).     */
+  /*                                                                       */
+  /*    pitch     :: The number of bytes per bitmap line.  May be positive */
+  /*                 or negative.                                          */
+  /*                                                                       */
+  /*    xadvance  :: The horizontal advance width in pixels.               */
+  /*                                                                       */
+  /*    yadvance  :: The vertical advance height in pixels.                */
+  /*                                                                       */
+  /*    buffer   :: A pointer to the bitmap pixels.                        */
+  /*                                                                       */
+  typedef struct  FTC_SBitRec_
+  {
+    FT_Byte   width;
+    FT_Byte   height;
+    FT_Char   left;
+    FT_Char   top;
+
+    FT_Byte   format;
+    FT_Byte   max_grays;
+    FT_Short  pitch;
+    FT_Char   xadvance;
+    FT_Char   yadvance;
+
+    FT_Byte*  buffer;
+
+  } FTC_SBitRec;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Type>                                                                */
+  /*    FTC_SBitCache                                                      */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    A handle to a small bitmap cache.  These are special cache objects */
+  /*    used to store small glyph bitmaps (and anti-aliased pixmaps) in a  */
+  /*    much more efficient way than the traditional glyph image cache     */
+  /*    implemented by @FTC_ImageCache.                                    */
+  /*                                                                       */
+  typedef struct FTC_SBitCacheRec_*  FTC_SBitCache;
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FTC_SBitCache_New                                                  */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Creates a new cache to store small glyph bitmaps.                  */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    manager :: A handle to the source cache manager.                   */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    acache  :: A handle to the new sbit cache.  NULL in case of error. */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
   /*                                                                       */
   FT_EXPORT( FT_Error )
-  FTC_Manager_Lookup_Size( FTC_Manager  manager,
-                           FTC_Font     font,
-                           FT_Face     *aface,
-                           FT_Size     *asize );
+  FTC_SBitCache_New( FTC_Manager     manager,
+                     FTC_SBitCache  *acache );
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FTC_SBitCache_Lookup                                               */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Looks up a given small glyph bitmap in a given sbit cache and      */
+  /*    "lock" it to prevent its flushing from the cache until needed      */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    cache  :: A handle to the source sbit cache.                       */
+  /*                                                                       */
+  /*    type   :: A pointer to the glyph image type descriptor.            */
+  /*                                                                       */
+  /*    gindex :: The glyph index.                                         */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    sbit   :: A handle to a small bitmap descriptor.                   */
+  /*                                                                       */
+  /*    anode  :: Used to return the address of of the corresponding cache */
+  /*              node after incrementing its reference count (see note    */
+  /*              below).                                                  */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    The small bitmap descriptor and its bit buffer are owned by the    */
+  /*    cache and should never be freed by the application.  They might    */
+  /*    as well disappear from memory on the next cache lookup, so don't   */
+  /*    treat them as persistent data.                                     */
+  /*                                                                       */
+  /*    The descriptor's `buffer' field is set to 0 to indicate a missing  */
+  /*    glyph bitmap.                                                      */
+  /*                                                                       */
+  /*    If "anode" is _not_ NULL, it receives the address of the cache     */
+  /*    node containing the bitmap, after increasing its reference count.  */
+  /*    This ensures that the node (as well as the image) will always be   */
+  /*    kept in the cache until you call @FTC_Node_Unref to "release" it.  */
+  /*                                                                       */
+  /*    If "anode" is NULL, the cache node is left unchanged, which means  */
+  /*    that the bitmap could be flushed out of the cache on the next      */
+  /*    call to one of the caching sub-system APIs.  Don't assume that it  */
+  /*    is persistent!                                                     */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FTC_SBitCache_Lookup( FTC_SBitCache    cache,
+                        FTC_ImageType    type,
+                        FT_UInt          gindex,
+                        FTC_SBit        *sbit,
+                        FTC_Node        *anode );
+
 
+ /* */
 
 FT_END_HEADER
 
diff --git a/include/freetype/ftstroke.h b/include/freetype/ftstroke.h
index a92c68d..93c189a 100644
--- a/include/freetype/ftstroke.h
+++ b/include/freetype/ftstroke.h
@@ -95,12 +95,113 @@ FT_BEGIN_HEADER
 
   } FT_Stroker_LineCap;
 
- /* */
 
+/**************************************************************
+ *
+ * @enum: FT_StrokerBorder
+ *
+ * @description:
+ *    theses values are used to select a given stroke border
+ *    in @FT_Stroker_GetBorderCounts and @FT_Stroker_ExportBorder
+ *
+ * @values:
+ *    FT_STROKER_BORDER_LEFT ::
+ *      select the left border, relative to the drawing direction
+ *
+ *    FT_STROKER_BORDER_RIGHT ::
+ *      select the right border, relative to the drawing direction
+ *
+ * @note:
+ *   applications are generally interested in the "inside" and "outside"
+ *   borders. However, there is no direct mapping between these and
+ *   the "left" / "right" ones, since this really depends on the glyph's
+ *   drawing orientation, which varies between font formats
+ *
+ *   you can however use @FT_Outline_GetInsideBorder and
+ *   @FT_Outline_GetOutsideBorder to get these.
+ */
+  typedef enum
+  {
+    FT_STROKER_BORDER_LEFT = 0,
+    FT_STROKER_BORDER_RIGHT
+  
+  } FT_StrokerBorder;
+
+
+/**************************************************************
+ *
+ * @function: FT_Outline_GetInsideBorder
+ *
+ * @description:
+ *    retrieve the @FT_StrokerBorder value corresponding to the
+ *    "inside" borders of a given outline
+ *
+ * @input:
+ *    outline :: source outline handle
+ *
+ * @return:
+ *    border index. @FT_STROKER_BORDER_LEFT for empty or invalid outlines
+ */
+  FT_EXPORT( FT_StrokerBorder )
+  FT_Outline_GetInsideBorder( FT_Outline*  outline );
+
+
+/**************************************************************
+ *
+ * @function: FT_Outline_GetOutsideBorder
+ *
+ * @description:
+ *    retrieve the @FT_StrokerBorder value corresponding to the
+ *    "outside" borders of a given outline
+ *
+ * @input:
+ *    outline :: source outline handle
+ *
+ * @return:
+ *    border index. @FT_STROKER_BORDER_LEFT for empty or invalid outlines
+ */
+  FT_EXPORT( FT_StrokerBorder )
+  FT_Outline_GetOutsideBorder( FT_Outline*  outline );
+
+ 
+/**************************************************************
+ *
+ * @function: FT_Stroker_New
+ *
+ * @description:
+ *    create a new stroker object
+ *
+ * @input:
+ *    memory :: memory manager handle
+ *
+ * @output:
+ *    new stroker object handle, NULL in case of error
+ *
+ * @return:
+ *    error code. 0 means success
+ */
   FT_EXPORT( FT_Error )
   FT_Stroker_New( FT_Memory    memory,
                   FT_Stroker  *astroker );
 
+
+/**************************************************************
+ *
+ * @function: FT_Stroker_Set
+ *
+ * @description:
+ *    reset a stroker object's attributes
+ *
+ * @input:
+ *    stroker     :: target stroker handle
+ *    radius      :: border radius
+ *    line_cap    :: line cap style
+ *    line_join   :: line join style
+ *    miter_limit :: miter limit for the FT_STROKER_LINEJOIN_MITER style,
+ *                   expressed as 16.16 fixed point value.
+ * @note:
+ *   the radius is expressed in the same units that the outline coordinates.
+ */
   FT_EXPORT( void )
   FT_Stroker_Set( FT_Stroker           stroker,
                   FT_Fixed             radius,
@@ -109,29 +210,152 @@ FT_BEGIN_HEADER
                   FT_Fixed             miter_limit );
 
 
+/**************************************************************
+ *
+ * @function: FT_Stroker_ParseOutline
+ *
+ * @description:
+ *    a convenient function used to parse a whole outline with
+ *    the stroker. The resulting outline(s) can be retrieved
+ *    later by functions like @FT_Stroker_GetCounts and @FT_Stroker_Export
+ *
+ * @input:
+ *    stroker     :: target stroker handle
+ *    outline     :: source outline
+ *    opened      :: boolean. if TRUE, the outline is treated as an open path,
+ *                   instead of a closed one
+ *
+ * @return:*
+ *   error code. 0 means success
+ *
+ * @note:
+ *   if 'opened' is 0 (the default), the outline is treated as a closed path,
+ *   and the stroker will generate two distinct "border" outlines
+ *
+ *   if 'opened' is 1, the outline is processed as an open path, and the
+ *   stroker will generate a single "stroke" outline
+ */
   FT_EXPORT( FT_Error )
   FT_Stroker_ParseOutline( FT_Stroker   stroker,
                            FT_Outline*  outline,
                            FT_Bool      opened );
 
+/**************************************************************
+ *
+ * @function: FT_Stroker_BeginSubPath
+ *
+ * @description:
+ *    start a new sub-path in the stroker
+ *    
+ * @input:
+ *    stroker     :: target stroker handle
+ *    to          :: pointer to start vector
+ *    open        :: boolean. if TRUE, the sub-path is treated as an open
+ *                   one
+ *
+ * @return:*
+ *   error code. 0 means success
+ *
+ * @note:
+ *   this function is useful when you need to stroke a path that is
+ *   not stored as a @FT_Outline object
+ */
   FT_EXPORT( FT_Error )
   FT_Stroker_BeginSubPath( FT_Stroker  stroker,
                            FT_Vector*  to,
                            FT_Bool     open );
 
+/**************************************************************
+ *
+ * @function: FT_Stroker_EndSubPath
+ *
+ * @description:
+ *    close the current sub-path in the stroker
+ *    
+ * @input:
+ *    stroker     :: target stroker handle
+ *
+ * @return:
+ *   error code. 0 means success
+ *
+ * @note:
+ *   you should call this function after @FT_Stroker_BeginSubPath.
+ *   if the subpath was not "opened", this function will "draw" a
+ *   single line segment to the start position when needed.
+ */
   FT_EXPORT( FT_Error )
   FT_Stroker_EndSubPath( FT_Stroker  stroker );
 
 
+/**************************************************************
+ *
+ * @function: FT_Stroker_LineTo
+ *
+ * @description:
+ *    "draw" a single line segment in the stroker's current sub-path,
+ *    from the last position
+ *    
+ * @input:
+ *    stroker     :: target stroker handle
+ *    to          :: pointer to destination point
+ *
+ * @return:
+ *   error code. 0 means success
+ *
+ * @note:
+ *   you should call this function between @FT_Stroker_BeginSubPath and
+ *   @FT_Stroker_EndSubPath
+ */
   FT_EXPORT( FT_Error )
   FT_Stroker_LineTo( FT_Stroker  stroker,
                      FT_Vector*  to );
 
+/**************************************************************
+ *
+ * @function: FT_Stroker_ConicTo
+ *
+ * @description:
+ *    "draw" a single quadratic bezier in the stroker's current sub-path,
+ *    from the last position
+ *    
+ * @input:
+ *    stroker     :: target stroker handle
+ *    control     :: pointer to bezier control point
+ *    to          :: pointer to destination point
+ *
+ * @return:
+ *   error code. 0 means success
+ *
+ * @note:
+ *   you should call this function between @FT_Stroker_BeginSubPath and
+ *   @FT_Stroker_EndSubPath
+ */
   FT_EXPORT( FT_Error )
   FT_Stroker_ConicTo( FT_Stroker  stroker,
                       FT_Vector*  control,
                       FT_Vector*  to );
 
+/**************************************************************
+ *
+ * @function: FT_Stroker_CubicTo
+ *
+ * @description:
+ *    "draw" a single cubic bezier in the stroker's current sub-path,
+ *    from the last position
+ *    
+ * @input:
+ *    stroker     :: target stroker handle
+ *    control1    :: pointer to first bezier control point
+ *    control2    :: pointer to second bezier control point
+ *    to          :: pointer to destination point
+ *
+ * @return:
+ *   error code. 0 means success
+ *
+ * @note:
+ *   you should call this function between @FT_Stroker_BeginSubPath and
+ *   @FT_Stroker_EndSubPath
+ */
   FT_EXPORT( FT_Error )
   FT_Stroker_CubicTo( FT_Stroker  stroker,
                       FT_Vector*  control1,
@@ -139,18 +363,166 @@ FT_BEGIN_HEADER
                       FT_Vector*  to );
 
 
+/**************************************************************
+ *
+ * @function: FT_Stroker_GetBorderCounts
+ *
+ * @description:
+ *    call this function once you finished parsing your paths
+ *    with the stroker. It will return the number of points and
+ *    contours necessary to export one of the "border" or "stroke"
+ *    outlines generated by the stroker.
+ *    
+ * @input:
+ *    stroker  :: target stroker handle
+ *    border   :: border index
+ *
+ * @output:
+ *    anum_points   :: number of points
+ *    anum_contours :: number of contours
+ *
+ * @return:
+ *   error code. 0 means success
+ *
+ * @note:
+ *   when an outline, or a sub-path, is "closed", the stroker generates
+ *   two independent 'border' outlines, named 'left' and 'right'
+ *   
+ *   when the outline, or a sub-path, is "opened", the stroker merges
+ *   the 'border' outlines with caps. The 'left' border receives all
+ *   points, while the 'right' border becomes empty.
+ *
+ *   use the function @FT_Stroker_GetCounts instead if you want to
+ *   retrieve the counts associated to both borders.
+ */
+  FT_EXPORT( FT_Error )
+  FT_Stroker_GetBorderCounts( FT_Stroker        stroker,
+                              FT_StrokerBorder  border,
+                              FT_UInt          *anum_points,
+                              FT_UInt          *anum_contours );
+
+/**************************************************************
+ *
+ * @function: FT_Stroker_ExportBorder
+ *
+ * @description:
+ *    call this function after @FT_Stroker_GetBorderCounts to
+ *    export the corresponding border to your own @FT_Outline
+ *    structure.
+ *    
+ *    note that this function will append the border points and
+ *    contours to your outline, but will not try to resize its
+ *    arrays.
+ *
+ * @input:
+ *    stroker  :: target stroker handle
+ *    border   :: border index
+ *    outline  :: target outline handle
+ *
+ * @return:
+ *   error code. 0 means success
+ *
+ * @note:
+ *   always call this function after @FT_Stroker_GetBorderCounts to
+ *   get sure that there is enough room in your @FT_Outline object to
+ *   receive all new data.
+ *
+ *   when an outline, or a sub-path, is "closed", the stroker generates
+ *   two independent 'border' outlines, named 'left' and 'right'
+ *   
+ *   when the outline, or a sub-path, is "opened", the stroker merges
+ *   the 'border' outlines with caps. The 'left' border receives all
+ *   points, while the 'right' border becomes empty.
+ *
+ *   use the function @FT_Stroker_Export instead if you want to
+ *   retrieve all borders at once
+ */
+  FT_EXPORT( void )
+  FT_Stroker_ExportBorder( FT_Stroker        stroker,
+                           FT_StrokerBorder  border,
+                           FT_Outline*       outline );
+
+/**************************************************************
+ *
+ * @function: FT_Stroker_GetCounts
+ *
+ * @description:
+ *    call this function once you finished parsing your paths
+ *    with the stroker. It will return the number of points and
+ *    contours necessary to export all points/borders from the stroked
+ *    outline/path.
+ *    
+ * @input:
+ *    stroker  :: target stroker handle
+ *
+ * @output:
+ *    anum_points   :: number of points
+ *    anum_contours :: number of contours
+ *
+ * @return:
+ *   error code. 0 means success
+ *
+ * @note:
+ */
   FT_EXPORT( FT_Error )
   FT_Stroker_GetCounts( FT_Stroker  stroker,
                         FT_UInt    *anum_points,
                         FT_UInt    *anum_contours );
 
+/**************************************************************
+ *
+ * @function: FT_Stroker_ExportBorder
+ *
+ * @description:
+ *    call this function after @FT_Stroker_GetBorderCounts to
+ *    export the corresponding border to your own @FT_Outline
+ *    structure.
+ *    
+ *    note that this function will append the border points and
+ *    contours to your outline, but will not try to resize its
+ *    arrays.
+ *
+ * @input:
+ *    stroker  :: target stroker handle
+ *    border   :: border index
+ *    outline  :: target outline handle
+ *
+ * @return:
+ *   error code. 0 means success
+ *
+ * @note:
+ *   always call this function after @FT_Stroker_GetBorderCounts to
+ *   get sure that there is enough room in your @FT_Outline object to
+ *   receive all new data.
+ *
+ *   when an outline, or a sub-path, is "closed", the stroker generates
+ *   two independent 'border' outlines, named 'left' and 'right'
+ *   
+ *   when the outline, or a sub-path, is "opened", the stroker merges
+ *   the 'border' outlines with caps. The 'left' border receives all
+ *   points, while the 'right' border becomes empty.
+ *
+ *   use the function @FT_Stroker_Export instead if you want to
+ *   retrieve all borders at once
+ */
   FT_EXPORT( void )
   FT_Stroker_Export( FT_Stroker   stroker,
                      FT_Outline*  outline );
 
+/**************************************************************
+ *
+ * @function: FT_Stroker_Done
+ *
+ * @description:
+ *    destroy a stroker object
+ *
+ * @input:
+ *    stroker :: stroker handle. can be NULL
+ */
   FT_EXPORT( void )
   FT_Stroker_Done( FT_Stroker  stroker );
 
+ /* */
 
 FT_END_HEADER
 
diff --git a/src/autofit/afhints.c b/src/autofit/afhints.c
index 9becdd5..3c1e10b 100644
--- a/src/autofit/afhints.c
+++ b/src/autofit/afhints.c
@@ -399,14 +399,14 @@
 
     hints->x_scale = x_scale;
     hints->y_scale = y_scale;
+    hints->x_delta = x_delta;
+    hints->y_delta = y_delta;
 
     points = hints->points;
     if ( hints->num_points == 0 )
       goto Exit;
 
     {
-      /* do one thing at a time -- it is easier to understand, and */
-      /* the code is clearer                                       */
       AF_Point  point;
       AF_Point  point_limit = points + hints->num_points;
 
diff --git a/src/autofit/afhints.h b/src/autofit/afhints.h
index 2f5f4ec..dda3753 100644
--- a/src/autofit/afhints.h
+++ b/src/autofit/afhints.h
@@ -163,7 +163,11 @@ FT_BEGIN_HEADER
     FT_Memory     memory;
 
     FT_Fixed      x_scale;
+    FT_Pos        x_delta;
+
     FT_Fixed      y_scale;
+    FT_Pos        y_delta;
+
     FT_Pos        edge_distance_threshold;
 
     FT_Int        max_points;
diff --git a/src/autofit/aflatin.c b/src/autofit/aflatin.c
index f748b11..70c563a 100644
--- a/src/autofit/aflatin.c
+++ b/src/autofit/aflatin.c
@@ -20,10 +20,7 @@
     metrics->axis[ AF_DIMENSION_HORZ ].width_count = 0;
     metrics->axis[ AF_DIMENSION_VERT ].width_count = 0;
 
-    /* For now, compute the standard width and height from the `o'       */
-    /* character.  I started computing the stem width of the `i' and the */
-    /* stem height of the "-", but it wasn't too good.  Moreover, we now */
-    /* have a single character that gives us standard width and height.  */
+    /* For now, compute the standard width and height from the `o' */
     {
       FT_UInt       glyph_index;
       AF_Dimension  dim;
diff --git a/src/autofit/aftypes.h b/src/autofit/aftypes.h
index 0bc9eb1..33cb464 100644
--- a/src/autofit/aftypes.h
+++ b/src/autofit/aftypes.h
@@ -40,14 +40,14 @@ FT_BEGIN_HEADER
     FT_Pos  org;  /* original position/width in font units              */
     FT_Pos  cur;  /* current/scaled position/width in device sub-pixels */
     FT_Pos  fit;  /* current/fitted position/width in device sub-pixels */
-  
+
   } AF_WidthRec, *AF_Width;
-  
+
 
   AF_LOCAL( void )
   af_sort_pos( FT_UInt   count,
                FT_Pos*   table );
- 
+
  /**************************************************************************/
  /**************************************************************************/
  /*****                                                                *****/
@@ -55,11 +55,11 @@ FT_BEGIN_HEADER
  /*****                                                                *****/
  /**************************************************************************/
  /**************************************************************************/
- 
+
  /*
   *  Angle type. The auto-fitter doesn't need a very high angular accuracy,
   *  and this allows us to speed up some computations considerably with a
-  *  light Cordic algorithm (see afangle.c)
+  *  light Cordic algorithm (see afangles.c)
   *
   */
 
@@ -111,10 +111,10 @@ FT_BEGIN_HEADER
     FT_Face          face;
     FT_OutlineRec    outline;
     FT_UInt          outline_resolution;
-    
+
     FT_Int           advance;
     FT_UInt          metrics_resolution;
-    
+
     AF_GlyphHints    hints;
 
   } AF_OutlineRec;
@@ -133,7 +133,7 @@ FT_BEGIN_HEADER
   *  auto-hinted glyph image
   *
   */
-  
+
   typedef enum
   {
     AF_SCALER_FLAG_NO_HORIZONTAL = 1,  /* disable horizontal hinting */
@@ -152,7 +152,7 @@ FT_BEGIN_HEADER
     FT_Pos          y_delta;      /* in 1/64th device pixels                 */
     FT_Render_Mode  render_mode;  /* monochrome, anti-aliased, LCD, etc..    */
     FT_UInt32       flags;        /* additionnal control flags, see above    */
-  
+
   } AF_ScalerRec, *AF_Scaler;
 
 
@@ -169,7 +169,7 @@ FT_BEGIN_HEADER
   *  the list of know scripts. Each different script correspond to the
   *  following information:
   *
-  *   - a set of Unicode ranges to test wether the face supports the
+  *   - a set of Unicode ranges to test weither the face supports the
   *     script
   *
   *   - a specific global analyzer that will compute global metrics
@@ -189,9 +189,9 @@ FT_BEGIN_HEADER
   {
     AF_SCRIPT_LATIN = 0,
     /* add new scripts here. don't forget to update the list in "afglobal.c" */
-    
+
     AF_SCRIPT_MAX   /* do not remove */
-  
+
   } AF_Script;
 
 
@@ -207,7 +207,7 @@ FT_BEGIN_HEADER
 
  /* this function parses a FT_Face to compute global metrics for
   * a specific script
-  */ 
+  */
   typedef FT_Error  (*AF_Script_InitMetricsFunc)( AF_ScriptMetrics   metrics,
                                                   FT_Face            face );
 
@@ -230,9 +230,9 @@ FT_BEGIN_HEADER
   {
     FT_UInt32    first;
     FT_UInt32    last;
-  
+
   } AF_Script_UniRangeRec, *AF_Script_UniRange;
- 
+
 
   typedef struct AF_ScriptClassRec_
   {
diff --git a/src/base/ftstroke.c b/src/base/ftstroke.c
index d6d5be3..2452a98 100644
--- a/src/base/ftstroke.c
+++ b/src/base/ftstroke.c
@@ -19,10 +19,31 @@
 #include <ft2build.h>
 #include FT_STROKER_H
 #include FT_TRIGONOMETRY_H
+#include FT_OUTLINE_H
 #include FT_INTERNAL_MEMORY_H
 #include FT_INTERNAL_DEBUG_H
 
 
+  FT_EXPORT_DEF( FT_StrokerBorder )
+  FT_Outline_GetInsideBorder( FT_Outline*  outline )
+  {
+    FT_Orientation  or = FT_Outline_Get_Orientation( outline );
+
+    return ( or == FT_ORIENTATION_TRUETYPE ) ? FT_STROKER_BORDER_RIGHT
+                                             : FT_STROKER_BORDER_LEFT ;
+  }
+
+
+  FT_EXPORT_DEF( FT_StrokerBorder )
+  FT_Outline_GetOutsideBorder( FT_Outline*  outline )
+  {
+    FT_Orientation  or = FT_Outline_Get_Orientation( outline );
+
+    return ( or == FT_ORIENTATION_TRUETYPE ) ? FT_STROKER_BORDER_RIGHT
+                                             : FT_STROKER_BORDER_LEFT ;
+  }
+
+
  /***************************************************************************/
  /***************************************************************************/
  /*****                                                                 *****/
@@ -221,6 +242,7 @@
     FT_Bool     movable;
     FT_Int      start;    /* index of current sub-path start point */
     FT_Memory   memory;
+    FT_Bool     valid;
 
   } FT_StrokeBorderRec, *FT_StrokeBorder;
 
@@ -468,6 +490,7 @@
     border->num_points = 0;
     border->max_points = 0;
     border->start      = -1;
+    border->valid      = 0;
   }
 
 
@@ -476,6 +499,7 @@
   {
     border->num_points = 0;
     border->start      = -1;
+    border->valid      = 0;
   }
 
 
@@ -491,6 +515,7 @@
     border->num_points = 0;
     border->max_points = 0;
     border->start      = -1;
+    border->valid      = 0;
   }
 
 
@@ -520,7 +545,7 @@
       }
       else if ( in_contour == 0 )
         goto Fail;
- 
+
       if ( tags[0] & FT_STROKE_TAG_END )
       {
         if ( in_contour == 0 )
@@ -534,6 +559,8 @@
     if ( in_contour != 0 )
       goto Fail;
 
+    border->valid = 1;
+
   Exit:
     *anum_points   = num_points;
     *anum_contours = num_contours;
@@ -661,8 +688,6 @@
     stroker->line_join   = line_join;
     stroker->miter_limit = miter_limit;
 
-    stroker->valid = 0;
-
     ft_stroke_border_reset( &stroker->borders[0] );
     ft_stroke_border_reset( &stroker->borders[1] );
   }
@@ -1424,6 +1449,34 @@
 
 
   FT_EXPORT_DEF( FT_Error )
+  FT_Stroker_GetBorderCounts( FT_Stroker        stroker,
+                              FT_StrokerBorder  border,
+                              FT_UInt          *anum_points,
+                              FT_UInt          *anum_contours )
+  {
+    FT_UInt   num_points = 0, num_contours = 0;
+    FT_Error  error;
+
+    if ( !stroker || border > 1 )
+    {
+      error = FT_Err_Invalid_Argument;
+      goto Exit;
+    }
+
+    error = ft_stroke_border_get_counts( stroker->borders + border,
+                                         &num_points, &num_contours );
+  Exit:
+    if ( anum_points )
+      *anum_points = num_points;
+
+    if ( anum_contours )
+      *anum_contours = num_contours;
+
+    return error;
+  }
+
+
+  FT_EXPORT_DEF( FT_Error )
   FT_Stroker_GetCounts( FT_Stroker  stroker,
                         FT_UInt    *anum_points,
                         FT_UInt    *anum_contours )
@@ -1446,8 +1499,6 @@
     num_points   = count1 + count3;
     num_contours = count2 + count4;
 
-    stroker->valid = 1;
-
   Exit:
     *anum_points   = num_points;
     *anum_contours = num_contours;
@@ -1456,17 +1507,32 @@
 
 
   FT_EXPORT_DEF( void )
-  FT_Stroker_Export( FT_Stroker   stroker,
+  FT_Stroker_ExportBorder( FT_Stroker        stroker,
+                           FT_StrokerBorder  border,
                      FT_Outline*  outline )
   {
-    if ( stroker->valid )
+    if ( border == FT_STROKER_BORDER_LEFT  ||
+         border == FT_STROKER_BORDER_RIGHT )
     {
-      ft_stroke_border_export( stroker->borders + 0, outline );
-      ft_stroke_border_export( stroker->borders + 1, outline );
+      FT_StrokeBorder  sborder = & stroker->borders[border];
+
+      if ( sborder->valid )
+        ft_stroke_border_export( sborder, outline );
     }
   }
 
 
+  FT_EXPORT_DEF( void )
+  FT_Stroker_Export( FT_Stroker   stroker,
+                     FT_Outline*  outline )
+  {
+    FT_Stroker_ExportBorder( stroker, FT_STROKER_BORDER_LEFT, outline );
+    FT_Stroker_ExportBorder( stroker, FT_STROKER_BORDER_RIGHT, outline );
+  }
+
+
+
+
   /*
    *  The following is very similar to FT_Outline_Decompose, except
    *  that we do support opened paths, and do not scale the outline.
diff --git a/src/cache/Jamfile b/src/cache/Jamfile
index 099fd5e..1981bee 100644
--- a/src/cache/Jamfile
+++ b/src/cache/Jamfile
@@ -14,7 +14,15 @@ HDRMACRO  [ FT2_SubDir  include ftcache.h ] ;
 
   if $(FT2_MULTI)
   {
-    _sources = ftlru ftcmanag ftccache ftcglyph ftcsbits ftcimage ftccmap ;
+    _sources = ftmru 
+               ftcmanag 
+               ftccache 
+               ftcglyph 
+               ftcsbits 
+               ftcimage
+               ftcbasic 
+               ftccmap 
+               ;
   }
   else
   {
diff --git a/src/cache/ftcache.c b/src/cache/ftcache.c
index 07e85e1..4e5c071 100644
--- a/src/cache/ftcache.c
+++ b/src/cache/ftcache.c
@@ -19,13 +19,13 @@
 #define FT_MAKE_OPTION_SINGLE_OBJECT
 
 #include <ft2build.h>
-#include "ftlru.c"
+#include "ftcmru.c"
 #include "ftcmanag.c"
 #include "ftccache.c"
+#include "ftccmap.c"
 #include "ftcglyph.c"
 #include "ftcimage.c"
 #include "ftcsbits.c"
-#include "ftccmap.c"
-
+#include "ftcbasic.c"
 
 /* END */
diff --git a/src/cache/ftcbasic.c b/src/cache/ftcbasic.c
new file mode 100644
index 0000000..7696cbe
--- /dev/null
+++ b/src/cache/ftcbasic.c
@@ -0,0 +1,380 @@
+#include <ft2build.h>
+#include FT_CACHE_H
+#include FT_CACHE_INTERNAL_GLYPH_H
+#include FT_CACHE_INTERNAL_IMAGE_H
+#include FT_CACHE_INTERNAL_SBITS_H
+#include FT_INTERNAL_MEMORY_H
+
+#include "ftcerror.h"
+
+
+ /*
+  *  Basic Families
+  *
+  *
+  */
+  typedef struct FTC_BasicAttrRec_
+  {
+    FTC_ScalerRec  scaler;
+    FT_UInt        load_flags;
+
+  } FTC_BasicAttrRec, *FTC_BasicAttrs;
+
+#define  FTC_BASIC_ATTR_COMPARE(a,b)                           \
+       ( FTC_SCALER_COMPARE( &(a)->scaler, &(b)->scaler ) &&   \
+         (a)->load_flags == (b)->load_flags                )
+
+#define  FTC_BASIC_ATTR_HASH(a)   \
+       ( FTC_SCALER_HASH(&(a)->scaler) + 31*(a)->load_flags )
+
+
+  typedef struct FTC_BasicQueryRec_
+  {
+    FTC_GQueryRec      gquery;
+    FTC_BasicAttrRec   attrs;
+
+  } FTC_BasicQueryRec, *FTC_BasicQuery;
+
+
+
+  typedef struct FTC_BasicFamilyRec_
+  {
+    FTC_FamilyRec      family;
+    FTC_BasicAttrRec   attrs;
+
+  } FTC_BasicFamilyRec, *FTC_BasicFamily;
+
+
+  static FT_Bool
+  ftc_basic_family_compare( FTC_BasicFamily   family,
+                            FTC_BasicQuery    query )
+  {
+    return FT_BOOL( FTC_BASIC_ATTR_COMPARE( &family->attrs, &query->attrs ) );
+  }
+
+  static FT_Error
+  ftc_basic_family_init( FTC_BasicFamily   family,
+                         FTC_BasicQuery    query,
+                         FTC_Cache         cache )
+  {
+    ftc_family_init( FTC_FAMILY( family ), cache );
+    family->attrs = query->attrs;
+    return 0;
+  }
+
+  static FT_Error
+  ftc_basic_family_reset( FTC_BasicFamily  family,
+                          FTC_BasicQuery   query )
+  {
+    family->attrs = query->attrs;
+    return 0;
+  }
+
+
+  static FT_Bool
+  ftc_basic_gnode_compare_faceid( FTC_GNode   gnode,
+                                  FTC_FaceID  face_id,
+                                  FTC_Cache   cache )
+  {
+    FTC_BasicFamily  family = (FTC_BasicFamily) gnode->family;
+    FT_Bool          result;
+
+    result = FT_BOOL( family->attrs.scaler.face_id == face_id );
+    if ( result )
+    {
+     /* we must call this function to avoid this node from appearing
+      * in later lookups with the same face_id !!
+      */
+      FTC_GNode_UnselectFamily( gnode, cache );
+    }
+    return result;
+  }
+
+
+  static FT_UInt
+  ftc_basic_family_get_count( FTC_BasicFamily  family,
+                              FTC_Manager      manager )
+  {
+    FT_Error  error;
+    FT_Face   face;
+    FT_UInt   result = 0;
+
+    error = FTC_Manager_LookupFace( manager, &family->attrs.scaler.face_id,
+                                    &face );
+    if ( !error )
+      result = face->num_glyphs;
+
+    return result;
+  }
+
+
+  static FT_Error
+  ftc_basic_family_load_bitmap( FTC_BasicFamily  family,
+                                FT_UInt          gindex,
+                                FTC_Manager      manager,
+                                FT_Face         *aface )
+  {
+    FT_Error  error;
+    FT_Size   size;
+
+    error = FTC_Manager_LookupSize( manager, &family->attrs.scaler, &size );
+    if ( !error )
+    {
+      FT_Face   face = size->face;
+
+      error = FT_Load_Glyph( face, gindex, family->attrs.load_flags |
+                                           FT_LOAD_RENDER );
+      if ( !error )
+        *aface = face;
+    }
+    return error;
+  }
+
+
+  static FT_Error
+  ftc_basic_family_load_glyph( FTC_BasicFamily  family,
+                               FT_UInt          gindex,
+                               FTC_Cache        cache,
+                               FT_Glyph        *aglyph )
+  {
+    FT_Error       error;
+    FTC_Scaler     scaler = &family->attrs.scaler;
+    FT_Face        face;
+    FT_Size        size;
+
+    /* we will now load the glyph image */
+    error = FTC_Manager_LookupSize( cache->manager,
+                                    scaler,
+                                    &size );
+    if ( !error )
+    {
+      face = size->face;
+
+      error = FT_Load_Glyph( face, gindex, family->attrs.load_flags );
+      if ( !error )
+      {
+        if ( face->glyph->format == FT_GLYPH_FORMAT_BITMAP  ||
+             face->glyph->format == FT_GLYPH_FORMAT_OUTLINE )
+        {
+          /* ok, copy it */
+          FT_Glyph  glyph;
+
+
+          error = FT_Get_Glyph( face->glyph, &glyph );
+          if ( !error )
+          {
+            *aglyph = glyph;
+            goto Exit;
+          }
+        }
+        else
+          error = FTC_Err_Invalid_Argument;
+      }
+    }
+  Exit:
+    return error;
+  }
+
+
+ /*
+  *
+  * basic image cache
+  *
+  */
+
+  static const FTC_IFamilyClassRec  ftc_basic_image_family_class =
+  {
+    {
+      sizeof( FTC_BasicFamilyRec ),
+      (FTC_MruNode_CompareFunc)  ftc_basic_family_compare,
+      (FTC_MruNode_InitFunc)     ftc_basic_family_init,
+      (FTC_MruNode_ResetFunc)    ftc_basic_family_reset,
+      (FTC_MruNode_DoneFunc)     NULL
+    },
+    (FTC_IFamily_LoadGlyphFunc)  ftc_basic_family_load_glyph
+  };
+
+
+
+  static const FTC_GCacheClassRec  ftc_basic_image_cache_class =
+  {
+    {
+      (FTC_Node_NewFunc)      FTC_INode_New,
+      (FTC_Node_WeightFunc)   FTC_INode_Weight,
+      (FTC_Node_CompareFunc)  FTC_GNode_Compare,
+      (FTC_Node_CompareFunc)  ftc_basic_gnode_compare_faceid,
+      (FTC_Node_FreeFunc)     FTC_INode_Free,
+
+      sizeof( FTC_GCacheRec ),
+      (FTC_Cache_InitFunc)    FTC_GCache_Init,
+      (FTC_Cache_DoneFunc)    FTC_GCache_Done
+    },
+    (FTC_MruListClass) & ftc_basic_image_family_class
+  };
+
+
+  FT_EXPORT_DEF( FT_Error )
+  FTC_ImageCache_New( FTC_Manager      manager,
+                      FTC_ImageCache  *acache )
+  {
+    return FTC_GCache_New( manager, & ftc_basic_image_cache_class,
+                           (FTC_GCache*) acache );
+  }
+
+
+  /* documentation is in ftcimage.h */
+
+  FT_EXPORT_DEF( FT_Error )
+  FTC_ImageCache_Lookup( FTC_ImageCache  cache,
+                         FTC_ImageType   type,
+                         FT_UInt         gindex,
+                         FT_Glyph       *aglyph,
+                         FTC_Node       *anode )
+  {
+    FTC_BasicQueryRec  query;
+    FTC_INode          node;
+    FT_Error           error;
+    FT_UInt32          hash;
+
+
+    /* some argument checks are delayed to FTC_Cache_Lookup */
+    if ( !aglyph )
+    {
+      error = FTC_Err_Invalid_Argument;
+      goto Exit;
+    }
+
+    *aglyph = NULL;
+    if ( anode )
+      *anode  = NULL;
+
+    query.attrs.scaler.face_id = type->face_id;
+    query.attrs.scaler.width   = type->width;
+    query.attrs.scaler.height  = type->height;
+    query.attrs.scaler.pixel   = 1;
+    query.attrs.load_flags     = type->flags;
+
+    hash = FTC_BASIC_ATTR_HASH( &query.attrs ) ^ (gindex << 8);
+
+    error = FTC_GCache_Lookup( FTC_GCACHE( cache ),
+                               hash, gindex,
+                               FTC_GQUERY( &query ),
+                               (FTC_Node*) &node );
+    if ( !error )
+    {
+      *aglyph = FTC_INODE(node)->glyph;
+
+      if ( anode )
+      {
+        *anode = FTC_NODE(node);
+        FTC_NODE(node)->ref_count++;
+      }
+    }
+
+  Exit:
+    return error;
+  }
+
+
+
+ /*
+  *
+  * basic small bitmap cache
+  *
+  */
+
+
+  static const FTC_SFamilyClassRec  ftc_basic_sbit_family_class =
+  {
+    {
+      sizeof( FTC_BasicFamilyRec ),
+      (FTC_MruNode_CompareFunc)  ftc_basic_family_compare,
+      (FTC_MruNode_InitFunc)     ftc_basic_family_init,
+      (FTC_MruNode_ResetFunc)    ftc_basic_family_reset,
+      (FTC_MruNode_DoneFunc)     NULL
+    },
+    (FTC_SFamily_GetCountFunc)   ftc_basic_family_get_count,
+    (FTC_SFamily_LoadGlyphFunc)  ftc_basic_family_load_bitmap
+  };
+
+
+  static const FTC_GCacheClassRec  ftc_basic_sbit_cache_class =
+  {
+    {
+      (FTC_Node_NewFunc)      FTC_SNode_New,
+      (FTC_Node_WeightFunc)   FTC_SNode_Weight,
+      (FTC_Node_CompareFunc)  FTC_SNode_Compare,
+      (FTC_Node_CompareFunc)  ftc_basic_gnode_compare_faceid,
+      (FTC_Node_FreeFunc)     FTC_SNode_Free,
+
+      sizeof( FTC_GCacheRec ),
+      (FTC_Cache_InitFunc)    FTC_GCache_Init,
+      (FTC_Cache_DoneFunc)    FTC_GCache_Done
+    },
+    (FTC_MruListClass) & ftc_basic_sbit_family_class
+  };
+
+
+
+
+  FT_EXPORT_DEF( FT_Error )
+  FTC_SBitCache_New( FTC_Manager     manager,
+                     FTC_SBitCache  *acache )
+  {
+    return FTC_GCache_New( manager, & ftc_basic_sbit_cache_class,
+                           (FTC_GCache*) acache );
+  }
+
+
+  FT_EXPORT_DEF( FT_Error )
+  FTC_SBitCache_Lookup( FTC_SBitCache   cache,
+                        FTC_ImageType   type,
+                        FT_UInt         gindex,
+                        FTC_SBit       *ansbit,
+                        FTC_Node       *anode )
+  {
+    FT_Error           error;
+    FTC_BasicQueryRec  query;
+    FTC_SNode          node;
+    FT_UInt32          hash;
+
+    if ( anode )
+      *anode = NULL;
+
+    /* other argument checks delayed to FTC_Cache_Lookup */
+    if ( !ansbit )
+      return FTC_Err_Invalid_Argument;
+
+    *ansbit = NULL;
+
+    query.attrs.scaler.face_id = type->face_id;
+    query.attrs.scaler.width   = type->width;
+    query.attrs.scaler.height  = type->height;
+    query.attrs.scaler.pixel   = 1;
+    query.attrs.load_flags     = type->flags;
+
+   /* beware, the hash must be the same for all glyph ranges !!
+    */
+    hash = FTC_BASIC_ATTR_HASH( &query.attrs ) ^
+           (gindex/FTC_SBIT_ITEMS_PER_NODE);
+
+    error = FTC_GCache_Lookup( FTC_GCACHE( cache ),
+                               hash,
+                               gindex,
+                               FTC_GQUERY( &query ),
+                               (FTC_Node*) &node );
+    if ( error )
+      goto Exit;
+
+    *ansbit = node->sbits + ( gindex - FTC_GNODE(node)->gindex );
+
+    if ( anode )
+    {
+      *anode = FTC_NODE( node );
+      FTC_NODE( node )->ref_count++;
+    }
+
+  Exit:
+    return error;
+  }
+
diff --git a/src/cache/ftccache.c b/src/cache/ftccache.c
index cc01c39..d5d2e41 100644
--- a/src/cache/ftccache.c
+++ b/src/cache/ftccache.c
@@ -17,7 +17,7 @@
 
 
 #include <ft2build.h>
-#include FT_CACHE_MANAGER_H
+#include FT_CACHE_INTERNAL_MANAGER_H
 #include FT_INTERNAL_OBJECTS_H
 #include FT_INTERNAL_DEBUG_H
 
@@ -40,23 +40,6 @@
   /*************************************************************************/
   /*************************************************************************/
 
-  FT_EXPORT_DEF( void )
-  ftc_node_done( FTC_Node   node,
-                 FTC_Cache  cache )
-  {
-    FTC_Family       family;
-    FTC_FamilyEntry  entry;
-
-
-    entry  = cache->manager->families.entries + node->fam_index;
-    family = entry->family;
-
-    /* remove from parent set table - eventually destroy the set */
-    if ( --family->num_nodes == 0 )
-      FT_LruList_Remove( cache->families, (FT_LruNode) family );
-  }
-
-
   /* add a new node to the head of the manager's circular MRU list */
   static void
   ftc_node_mru_link( FTC_Node     node,
@@ -152,96 +135,158 @@
   }
 
 
+ /* note that this function cannot fail. If we cannot re-size the
+  * buckets array appropriately, we simply degrade the hash table's
+  * performance !!
+  */
+  static void
+  ftc_cache_resize( FTC_Cache  cache )
+  {
+    for (;;)
+    {
+      FTC_Node   node, *pnode;
+      FT_UInt    p      = cache->p;
+      FT_UInt    mask   = cache->mask;
+      FT_UInt    count  = mask + p + 1;    /* number of buckets */
+
+     /* do we need to shrink the buckets array ?
+      */
+      if ( cache->slack < 0 )
+      {
+        FTC_Node   new_list = NULL;
+
+        /* try to expand the buckets array _before_ splitting
+         * the bucket lists
+         */
+         if ( p >= mask )
+         {
+           FT_Memory  memory = cache->memory;
+
+          /* if we can't expand the array, leave immediately */
+           if ( FT_MEM_RENEW_ARRAY( cache->buckets, (mask+1)*2, (mask+1)*4 ) )
+             break;
+         }
+
+        /* split a single bucket */
+         pnode = cache->buckets + p;
+
+         for (;;)
+         {
+           node = *pnode;
+           if ( node == NULL )
+             break;
+
+           if ( node->hash & ( mask + 1 ) )
+           {
+             *pnode     = node->link;
+             node->link = new_list;
+             new_list   = node;
+           }
+           else
+             pnode = &node->link;
+         }
+
+         cache->buckets[p + mask + 1] = new_list;
+
+         cache->slack += FTC_HASH_MAX_LOAD;
+
+        if ( p >= mask )
+        {
+          cache->mask = 2 * mask + 1;
+          cache->p    = 0;
+        }
+        else
+          cache->p = p + 1;
+      }
+     /* do we need to expand the buckets array ?
+      */
+      else if ( cache->slack > (FT_Long)count * FTC_HASH_SUB_LOAD )
+      {
+        FT_UInt    old_index = p + mask;
+        FTC_Node*  pold;
+
+        if ( old_index + 1 <= FTC_HASH_INITIAL_SIZE )
+          break;
+
+        if ( p == 0 )
+        {
+          FT_Memory  memory = cache->memory;
+
+         /* if we can't shrink the array, leave immediately */
+          if ( FT_MEM_RENEW_ARRAY( cache->buckets, ( mask + 1 ) * 2, (mask+1) ) )
+            break;
+
+          cache->mask >>= 1;
+          p             = cache->mask;
+        }
+        else
+          p--;
+
+        pnode = cache->buckets + p;
+        while ( *pnode )
+          pnode = &(*pnode)->link;
+
+        pold   = cache->buckets + old_index;
+        *pnode = *pold;
+        *pold  = NULL;
+
+        cache->slack -= FTC_HASH_MAX_LOAD;
+        cache->p      = p;
+      }
+      else /* the hash table is balanced */
+        break;
+    }
+  }
+
+
+
   /* remove a node from its cache's hash table */
-  static FT_Error
-  ftc_node_hash_unlink( FTC_Node   node,
+  static void
+  ftc_node_hash_unlink( FTC_Node   node0,
                         FTC_Cache  cache )
   {
-    FT_Error   error = 0;
     FTC_Node  *pnode;
-    FT_UInt    idx, num_buckets;
+    FT_UInt    idx;
 
 
-    idx = (FT_UInt)( node->hash & cache->mask );
+    idx = (FT_UInt)( node0->hash & cache->mask );
     if ( idx < cache->p )
-      idx = (FT_UInt)( node->hash & ( 2 * cache->mask + 1 ) );
+      idx = (FT_UInt)( node0->hash & ( 2 * cache->mask + 1 ) );
 
     pnode = cache->buckets + idx;
 
     for (;;)
     {
-      if ( *pnode == NULL )
+      FTC_Node  node = *pnode;
+
+      if ( node == NULL )
       {
         FT_ERROR(( "ftc_node_hash_unlink: unknown node!\n" ));
-        return FTC_Err_Ok;
+        return;
       }
 
-      if ( *pnode == node )
-      {
-        *pnode     = node->link;
-        node->link = NULL;
+      if ( node == node0 )
         break;
-      }
 
       pnode = &(*pnode)->link;
     }
 
-    num_buckets = ( cache->p + cache->mask + 1 );
-
-    if ( ++cache->slack > (FT_Long)num_buckets * FTC_HASH_SUB_LOAD )
-    {
-      FT_UInt    p         = cache->p;
-      FT_UInt    mask      = cache->mask;
-      FT_UInt    old_index = p + mask;
-      FTC_Node*  pold;
-
-
-      if ( old_index + 1 <= FTC_HASH_INITIAL_SIZE )
-        goto Exit;
-
-      if ( p == 0 )
-      {
-        FT_Memory  memory = cache->memory;
-
-
-        cache->mask >>= 1;
-        p             = cache->mask;
-
-        if ( FT_RENEW_ARRAY( cache->buckets, ( mask + 1 ) * 2, (mask+1) ) )
-        {
-          FT_ERROR(( "ftc_node_hash_unlink: couldn't shunk buckets!\n" ));
-          goto Exit;
-        }
-      }
-      else
-        p--;
-
-      pnode = cache->buckets + p;
-      while ( *pnode )
-        pnode = &(*pnode)->link;
-
-      pold   = cache->buckets + old_index;
-      *pnode = *pold;
-      *pold  = NULL;
+    *pnode      = node0->link;
+    node0->link = NULL;
 
-      cache->slack -= FTC_HASH_MAX_LOAD;
-      cache->p      = p;
-    }
-
-  Exit:
-    return error;
+    cache->slack++;
+    ftc_cache_resize( cache );
   }
 
 
 
   /* add a node to the "top" of its cache's hash table */
-  static FT_Error
+  static void
   ftc_node_hash_link( FTC_Node   node,
                       FTC_Cache  cache )
   {
     FTC_Node  *pnode;
     FT_UInt    idx;
-    FT_Error   error = 0;
 
 
     idx = (FT_UInt)( node->hash & cache->mask );
@@ -253,58 +298,8 @@
     node->link = *pnode;
     *pnode     = node;
 
-    if ( --cache->slack < 0 )
-    {
-      FT_UInt    p     = cache->p;
-      FT_UInt    mask  = cache->mask;
-      FTC_Node   new_list;
-
-
-      /* split a single bucket */
-      new_list = NULL;
-      pnode    = cache->buckets + p;
-
-      for (;;)
-      {
-        node = *pnode;
-        if ( node == NULL )
-          break;
-
-        if ( node->hash & ( mask + 1 ) )
-        {
-          *pnode     = node->link;
-          node->link = new_list;
-          new_list   = node;
-        }
-        else
-          pnode = &node->link;
-      }
-
-      cache->buckets[p + mask + 1] = new_list;
-
-      cache->slack += FTC_HASH_MAX_LOAD;
-
-      if ( p >= mask )
-      {
-        FT_Memory  memory = cache->memory;
-
-
-        if ( FT_RENEW_ARRAY( cache->buckets,
-                             ( mask + 1 ) * 2, ( mask + 1 ) * 4 ) )
-        {
-          FT_ERROR(( "ftc_node_hash_link: couldn't expand buckets!\n" ));
-          goto Exit;
-        }
-
-        cache->mask = 2 * mask + 1;
-        cache->p    = 0;
-      }
-      else
-        cache->p = p + 1;
-    }
-
-  Exit:
-    return error;
+    cache->slack--;
+    ftc_cache_resize( cache );
   }
 
 
@@ -315,23 +310,19 @@
   ftc_node_destroy( FTC_Node     node,
                     FTC_Manager  manager )
   {
-    FT_Memory        memory  = manager->library->memory;
-    FTC_Cache        cache;
-    FTC_FamilyEntry  entry;
-    FTC_Cache_Class  clazz;
+    FTC_Cache  cache;
 
 
 #ifdef FT_DEBUG_ERROR
     /* find node's cache */
-    if ( node->fam_index >= manager->families.count )
+    if ( node->cache_index >= manager->num_caches )
     {
       FT_ERROR(( "ftc_node_destroy: invalid node handle\n" ));
       return;
     }
 #endif
 
-    entry = manager->families.entries + node->fam_index;
-    cache = entry->cache;
+    cache = manager->caches[ node->cache_index ];
 
 #ifdef FT_DEBUG_ERROR
     if ( cache == NULL )
@@ -341,9 +332,7 @@
     }
 #endif
 
-    clazz = cache->clazz;
-
-    manager->cur_weight -= clazz->node_weight( node, cache );
+    manager->cur_weight -= cache->clazz.node_weight( node, cache );
 
     /* remove node from mru list */
     ftc_node_mru_unlink( node, manager );
@@ -352,10 +341,7 @@
     ftc_node_hash_unlink( node, cache );
 
     /* now finalize it */
-    if ( clazz->node_done )
-      clazz->node_done( node, cache );
-
-    FT_FREE( node );
+    cache->clazz.node_free( node, cache );
 
 #if 0
     /* check, just in case of general corruption :-) */
@@ -369,120 +355,34 @@
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
-  /*****                   CACHE FAMILY DEFINITIONS                    *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-
-
-  FT_EXPORT_DEF( FT_Error )
-  ftc_family_init( FTC_Family  family,
-                   FTC_Query   query,
-                   FTC_Cache   cache )
-  {
-    FT_Error         error;
-    FTC_Manager      manager = cache->manager;
-    FT_Memory        memory  = manager->library->memory;
-    FTC_FamilyEntry  entry;
-
-
-    family->cache     = cache;
-    family->num_nodes = 0;
-
-    /* now add to manager's family table */
-    error = ftc_family_table_alloc( &manager->families, memory, &entry );
-    if ( !error )
-    {
-      entry->cache      = cache;
-      entry->family     = family;
-      family->fam_index = entry->index;
-
-      query->family = family;   /* save family in query */
-    }
-
-    return error;
-  }
-
-
-  FT_EXPORT_DEF( void )
-  ftc_family_done( FTC_Family  family )
-  {
-    if ( family && family->cache )
-    {
-      FTC_Manager  manager = family->cache->manager;
-
-
-      /* remove from manager's family table */
-      ftc_family_table_free( &manager->families, family->fam_index );
-    }
-  }
-
-
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
   /*****                    ABSTRACT CACHE CLASS                       *****/
   /*****                                                               *****/
   /*************************************************************************/
   /*************************************************************************/
 
 
-
-  FT_EXPORT_DEF( FT_Error )
-  ftc_cache_init( FTC_Cache  cache )
+  FT_EXPORT( FT_Error )
+  FTC_Cache_Init( FTC_Cache       cache )
   {
-    FT_Memory        memory = cache->memory;
-    FTC_Cache_Class  clazz  = cache->clazz;
-    FT_Error         error;
-
+    FT_Memory  memory = cache->memory;
 
-    cache->p     = 0;
-    cache->mask  = FTC_HASH_INITIAL_SIZE - 1;
-    cache->slack = FTC_HASH_INITIAL_SIZE * FTC_HASH_MAX_LOAD;
+    cache->p       = 0;
+    cache->mask    = FTC_HASH_INITIAL_SIZE - 1;
+    cache->slack   = FTC_HASH_INITIAL_SIZE * FTC_HASH_MAX_LOAD;
 
-    if ( FT_NEW_ARRAY( cache->buckets, FTC_HASH_INITIAL_SIZE * 2 ) )
-      goto Exit;
-
-    /* now, initialize the lru list of families for this cache */
-    if ( clazz->family_size > 0 )
-    {
-      FT_LruList_ClassRec*  lru_class = &cache->family_class;
-
-
-      lru_class->list_size = sizeof( FT_LruListRec );
-      lru_class->list_init = NULL;
-      lru_class->list_done = NULL;
-
-      lru_class->node_size    = clazz->family_size;
-      lru_class->node_init    = (FT_LruNode_InitFunc)   clazz->family_init;
-      lru_class->node_done    = (FT_LruNode_DoneFunc)   clazz->family_done;
-      lru_class->node_flush   = (FT_LruNode_FlushFunc)  NULL;
-      lru_class->node_compare = (FT_LruNode_CompareFunc)clazz->family_compare;
-
-      error = FT_LruList_New( (FT_LruList_Class) lru_class,
-                              0,    /* max items == 0 => unbounded list */
-                              cache,
-                              memory,
-                              &cache->families );
-      if ( error )
-        FT_FREE( cache->buckets );
-    }
-
-  Exit:
-    return error;
+    return ( FT_MEM_NEW_ARRAY( cache->buckets, FTC_HASH_INITIAL_SIZE * 2 ) );
   }
 
 
+
   FT_EXPORT_DEF( void )
-  ftc_cache_clear( FTC_Cache  cache )
+  FTC_Cache_Clear( FTC_Cache  cache )
   {
     if ( cache )
     {
-      FT_Memory        memory  = cache->memory;
-      FTC_Cache_Class  clazz   = cache->clazz;
-      FTC_Manager      manager = cache->manager;
-      FT_UFast         i;
-      FT_UInt          count;
+      FTC_Manager  manager = cache->manager;
+      FT_UFast     i;
+      FT_UInt      count;
 
       count = cache->p + cache->mask + 1;
 
@@ -500,310 +400,228 @@
           ftc_node_mru_unlink( node, manager );
 
           /* now finalize it */
-          manager->cur_weight -= clazz->node_weight( node, cache );
+          manager->cur_weight -= cache->clazz.node_weight( node, cache );
 
-          if ( clazz->node_done )
-            clazz->node_done( node, cache );
-
-          FT_FREE( node );
+          cache->clazz.node_free( node, cache );
           node = next;
         }
         cache->buckets[i] = NULL;
       }
-
-      cache->p = 0;
-
-      /* destroy the families */
-      if ( cache->families )
-        FT_LruList_Reset( cache->families );
+      ftc_cache_resize( cache );
     }
   }
 
 
-  FT_EXPORT_DEF( void )
-  ftc_cache_done( FTC_Cache  cache )
+  FT_EXPORT( void )
+  FTC_Cache_Done( FTC_Cache  cache )
   {
-    if ( cache )
+    if ( cache->memory )
     {
       FT_Memory  memory = cache->memory;
 
-
-      ftc_cache_clear( cache );
+      FTC_Cache_Clear( cache );
 
       FT_FREE( cache->buckets );
       cache->mask  = 0;
+      cache->p     = 0;
       cache->slack = 0;
 
-      if ( cache->families )
-      {
-        FT_LruList_Destroy( cache->families );
-        cache->families = NULL;
-      }
+      cache->memory = NULL;
     }
   }
 
 
-  /* Look up a node in "top" of its cache's hash table. */
-  /* If not found, create a new node.                   */
-  /*                                                    */
-  FT_EXPORT_DEF( FT_Error )
-  ftc_cache_lookup( FTC_Cache   cache,
-                    FTC_Query   query,
-                    FTC_Node   *anode )
-  {
-    FT_Error     error = FTC_Err_Ok;
-    FTC_Manager  manager;
-    FT_LruNode   lru;
-    FT_UInt      free_count = 0;
-
-
-    if ( !cache || !query || !anode )
-      return FTC_Err_Invalid_Argument;
-
-    *anode = NULL;
 
-    query->hash   = 0;
-    query->family = NULL;
-
-    manager = cache->manager;
+  static void
+  ftc_cache_add( FTC_Cache    cache,
+                 FT_UInt32    hash,
+                 FTC_Node     node )
+  {
+    node->hash = hash;
 
-   /*  here's a small note explaining what's happening in the code below.
-    *
-    *  We need to deal intelligently with out-of-memory (OOM) conditions
-    *  when trying to create a new family or cache node during the lookup.
-    *
-    *  When an OOM is detected, we try to free one or more "old" nodes
-    *  from the cache, then try again.  It may be necessary to do that
-    *  several times, so a loop is needed.
-    *
-    *  The local variable "free_count" holds the number of "old" nodes to
-    *  discard on each attempt.  It starts at 1 and doubles on each
-    *  iteration.  The loop stops when:
-    *
-    *   - a non-OOM error is detected
-    *   - a succesful lookup is performed
-    *   - there are no more unused nodes in the cache
-    *
-    *  For the record, remember that all used nodes appear _before_
-    *  unused ones in the manager's MRU node list.
-    */
+    ftc_node_hash_link( node, cache );
+    ftc_node_mru_link( node, cache->manager );
 
-    for (;;)
     {
-      {
-        /* first of all, find the relevant family */
-        FT_LruList              list    = cache->families;
-        FT_LruNode              fam, *pfam;
-        FT_LruNode_CompareFunc  compare = list->clazz->node_compare;
-
-        pfam = &list->nodes;
-        for (;;)
-        {
-          fam = *pfam;
-          if ( fam == NULL )
-          {
-            error = FT_LruList_Lookup( list, query, &lru );
-            if ( error )
-              goto Fail;
+      FTC_Manager  manager = cache->manager;
 
-            goto Skip;
-          }
+      manager->cur_weight += cache->clazz.node_weight( node, cache );
 
-          if ( compare( fam, query, list->data ) )
-            break;
-
-          pfam = &fam->next;
-        }
+      if ( manager->cur_weight >= manager->max_weight )
+      {
+        node->ref_count++;
+        FTC_Manager_Compress( manager );
+        node->ref_count--;
+      }
+    }
+  }
 
-        FT_ASSERT( fam != NULL );
 
-        /* move to top of list when needed */
-        if ( fam != list->nodes )
-        {
-          *pfam       = fam->next;
-          fam->next   = list->nodes;
-          list->nodes = fam;
-        }
+  FT_EXPORT( FT_Error )
+  FTC_Cache_Lookup( FTC_Cache   cache,
+                    FT_UInt32   hash,
+                    FT_Pointer  query,
+                    FTC_Node   *anode )
+  {
+    FT_UFast   idx;
+    FTC_Node*  bucket;
+    FTC_Node*  pnode;
+    FTC_Node   node;
+    FT_Error   error = 0;
 
-        lru = fam;
+    FTC_Node_CompareFunc  compare = cache->clazz.node_compare;
 
-      Skip:
-        ;
-      }
 
-      {
-        FTC_Family   family  = (FTC_Family) lru;
-        FT_UFast     hash    = query->hash;
-        FTC_Node*    bucket;
-        FT_UInt      idx;
+    if ( cache == NULL || anode == NULL )
+      return FT_Err_Invalid_Argument;
 
+    idx = hash & cache->mask;
+    if ( idx < cache->p )
+      idx = hash & ( cache->mask * 2 + 1 );
 
-        idx = hash & cache->mask;
-        if ( idx < cache->p )
-          idx = hash & ( cache->mask * 2 + 1 );
+    bucket = cache->buckets + idx;
+    pnode  = bucket;
+    for (;;)
+    {
+      node = *pnode;
+      if ( node == NULL )
+        goto NewNode;
 
-        bucket  = cache->buckets + idx;
+      if ( node->hash == hash && compare( node, query, cache ) )
+        break;
 
+      pnode = &node->link;
+    }
 
-        if ( query->family     != family                 ||
-             family->fam_index >= manager->families.size )
-        {
-          FT_ERROR((
-            "ftc_cache_lookup: invalid query (bad 'family' field)\n" ));
-          error = FTC_Err_Invalid_Argument;
-          goto Exit;
-        }
+    if ( node != *bucket )
+    {
+      *pnode     = node->link;
+      node->link = *bucket;
+      *bucket    = node;
+    }
 
-        if ( *bucket )
-        {
-          FTC_Node*             pnode   = bucket;
-          FTC_Node_CompareFunc  compare = cache->clazz->node_compare;
+    /* move to head of MRU list */
+    {
+      FTC_Manager  manager = cache->manager;
 
+      if ( node != manager->nodes_list )
+        ftc_node_mru_up( node, manager );
+    }
+    goto Exit;
 
-          for ( ;; )
-          {
-            FTC_Node  node;
+  NewNode:
 
+   /*
+    *  try to allocate a new cache node. Note that in case of
+    *  out-of-memory error (OOM), we'll flush the cache a bit,
+    *  then try again.
+    *
+    *  on each try, the "tries" variable gives the number
+    *  of old nodes we want to flush from the manager's global list
+    *  before the next allocation attempt. it barely doubles on
+    *  each iteration
+    *
+    */
+    error = cache->clazz.node_new( &node, query, cache );
+    if ( !error )
+      goto AddNode;
 
-            node = *pnode;
-            if ( node == NULL )
-              break;
+    node = NULL;
+    if ( error != FT_Err_Out_Of_Memory )
+      goto Exit;
 
-            if ( node->hash == hash                            &&
-                 (FT_UInt)node->fam_index == family->fam_index &&
-                 compare( node, query, cache ) )
-            {
-              /* move to head of bucket list */
-              if ( pnode != bucket )
-              {
-                *pnode     = node->link;
-                node->link = *bucket;
-                *bucket    = node;
-              }
+    {
+      FTC_Manager  manager = cache->manager;
+      FT_UInt      count, tries = 1;
 
-              /* move to head of MRU list */
-              if ( node != manager->nodes_list )
-                ftc_node_mru_up( node, manager );
+      for (;;)
+      {
+        error = cache->clazz.node_new( &node, query, cache );
+        if ( !error )
+          break;
 
-              *anode = node;
-              goto Exit;
-            }
+        node = NULL;
+        if ( error != FT_Err_Out_Of_Memory )
+          goto Exit;
 
-            pnode = &node->link;
-          }
-        }
+        count = FTC_Manager_FlushN( manager, tries );
+        if ( count == 0 )
+          goto Exit;
 
-        /* didn't find a node, create a new one */
+        if ( count == tries )
         {
-          FTC_Cache_Class  clazz   = cache->clazz;
-          FT_Memory        memory  = cache->memory;
-          FTC_Node         node;
-
-
-          if ( FT_ALLOC( node, clazz->node_size ) )
-            goto Fail;
-
-          node->fam_index = (FT_UShort) family->fam_index;
-          node->hash      = query->hash;
-          node->ref_count = 0;
-
-          error = clazz->node_init( node, query, cache );
-          if ( error )
-          {
-            FT_FREE( node );
-            goto Fail;
-          }
-
-          error = ftc_node_hash_link( node, cache );
-          if ( error )
-          {
-            clazz->node_done( node, cache );
-            FT_FREE( node );
-            goto Fail;
-          }
-
-          ftc_node_mru_link( node, cache->manager );
-
-          cache->manager->cur_weight += clazz->node_weight( node, cache );
-
-          /* now try to compress the node pool when necessary */
-          if ( manager->cur_weight >= manager->max_weight )
-          {
-            node->ref_count++;
-            FTC_Manager_Compress( manager );
-            node->ref_count--;
-          }
-
-          *anode = node;
+          count = tries*2;
+          if ( count < tries || count > manager->num_nodes )
+            count = manager->num_nodes;
         }
-
-       /* all is well, exit now
-        */
-        goto Exit;
+        tries = count;
       }
+    }
 
-    Fail:
-      if ( error != FTC_Err_Out_Of_Memory )
-        goto Exit;
-
-     /* There is not enough memory; try to release some unused nodes
-      * from the cache to make room for a new one.
-      */
-      {
-        FT_UInt  new_count;
+  AddNode:
+   /* don't assume that the cache has the same number of buckets, since
+    * our allocation request might have triggered global cache flushing
+    */
+    ftc_cache_add( cache, hash, node );
 
+  Exit:
+    *anode = node;
+    return error;
+  }
 
-        new_count = 1 + free_count * 2;
 
-        /* check overflow and bounds */
-        if ( new_count < free_count || free_count > manager->num_nodes )
-          goto Exit;
 
-        free_count = new_count;
 
-        /* try to remove "new_count" nodes from the list */
-        {
-          FTC_Node  first = manager->nodes_list;
-          FTC_Node  node;
+  FT_EXPORT( void )
+  FTC_Cache_RemoveFaceID( FTC_Cache    cache,
+                           FTC_FaceID   face_id )
+  {
+    FT_UFast     i, count;
+    FTC_Manager  manager = cache->manager;
+    FTC_Node     free    = NULL;
 
+    count = cache->p + cache->mask;
+    for ( i = 0; i < count; i++ )
+    {
+      FTC_Node*  bucket = cache->buckets + i;
+      FTC_Node*  pnode  = bucket;
 
-          if ( first == NULL )  /* empty list! */
-            goto Exit;
+      for ( ;; )
+      {
+        FTC_Node  node = *pnode;
 
-          /* go to last node - it's a circular list */
-          node = first->mru_prev;
-          for ( ; node && new_count > 0; new_count-- )
-          {
-            FTC_Node  prev = node->mru_prev;
+        if ( node == NULL )
+          break;
 
+        if ( cache->clazz.node_remove_faceid( node, face_id, cache ) )
+        {
+          *pnode = node->link;
+          node->link = free;
+          free       = node;
+        }
+        else
+          pnode = &node->link;
+      }
+    }
 
-            /* Used nodes always appear before unused one in the MRU
-             * list.  If we find one here, we'd better stop right now
-             * our iteration.
-             */
-            if ( node->ref_count > 0 )
-            {
-              /* if there are no unused nodes in the list, we'd better exit */
-              if ( new_count == free_count )
-                goto Exit;
+   /* remove all nodes in the free list
+    */
+    while ( free )
+    {
+      FTC_Node  node;
 
-              break;
-            }
+      node = free;
+      free = node->link;
 
-            ftc_node_destroy( node, manager );
+      manager->cur_weight -= cache->clazz.node_weight( node, cache );
+      ftc_node_mru_unlink( node, manager );
 
-            if ( node == first )
-              break;
+      cache->clazz.node_free( node, cache );
 
-            node = prev;
-          }
-        }
-      }
+      cache->slack ++;
     }
 
-  Exit:
-    return error;
+    ftc_cache_resize( cache );
   }
 
-
 /* END */
diff --git a/src/cache/ftccmap.c b/src/cache/ftccmap.c
index bdb83ab..b107daa 100644
--- a/src/cache/ftccmap.c
+++ b/src/cache/ftccmap.c
@@ -19,8 +19,7 @@
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include FT_CACHE_H
-#include FT_CACHE_CHARMAP_H
-#include FT_CACHE_MANAGER_H
+#include FT_CACHE_INTERNAL_MANAGER_H
 #include FT_INTERNAL_MEMORY_H
 #include FT_INTERNAL_DEBUG_H
 #include FT_TRUETYPE_IDS_H
@@ -47,56 +46,41 @@
   /* number of glyph indices / character code per node */
 #define FTC_CMAP_INDICES_MAX  128
 
+  /* compute a query/node hash */
+#define  FTC_CMAP_HASH( faceid, index, charcode )    \
+   ( FTC_FACE_ID_HASH( faceid ) + 211*( index ) + ((char_code) / FTC_CMAP_INDICES_MAX) )
 
+  /* the charmap query */
+  typedef struct  FTC_CMapQueryRec_
+  {
+    FTC_FaceID    face_id;
+    FT_UInt       cmap_index;
+    FT_UInt32     char_code;
+
+  } FTC_CMapQueryRec, *FTC_CMapQuery;
+
+#define  FTC_CMAP_QUERY(x)  ((FTC_CMapQuery)(x))
+#define  FTC_CMAP_QUERY_HASH(x)  FTC_CMAP_HASH( (x)->face_id, (x)->cmap_index, (x)->char_code )
+
+ /* the cmap cache node */
   typedef struct  FTC_CMapNodeRec_
   {
     FTC_NodeRec  node;
+    FTC_FaceID   face_id;
+    FT_UInt      cmap_index;
     FT_UInt32    first;                         /* first character in node */
     FT_UInt16    indices[FTC_CMAP_INDICES_MAX]; /* array of glyph indices  */
 
   } FTC_CMapNodeRec, *FTC_CMapNode;
 
-
 #define FTC_CMAP_NODE( x ) ( (FTC_CMapNode)( x ) )
-
-
-  /* compute node hash value from cmap family and "requested" glyph index */
-#define FTC_CMAP_HASH( cfam, cquery )                                       \
-          ( (cfam)->hash + ( (cquery)->char_code / FTC_CMAP_INDICES_MAX ) )
+#define FTC_CMAP_NODE_HASH(x)  FTC_CMAP_HASH( (x)->face_id, (x)->cmap_index, (x)->first )
 
   /* if (indices[n] == FTC_CMAP_UNKNOWN), we assume that the corresponding */
   /* glyph indices haven't been queried through FT_Get_Glyph_Index() yet   */
 #define FTC_CMAP_UNKNOWN  ( (FT_UInt16)-1 )
 
 
-  /* the charmap query */
-  typedef struct  FTC_CMapQueryRec_
-  {
-    FTC_QueryRec  query;
-    FTC_CMapDesc  desc;
-    FT_UInt32     char_code;
-
-  } FTC_CMapQueryRec, *FTC_CMapQuery;
-
-
-#define FTC_CMAP_QUERY( x )  ( (FTC_CMapQuery)( x ) )
-
-
-  /* the charmap family */
-  typedef struct FTC_CMapFamilyRec_
-  {
-    FTC_FamilyRec    family;
-    FT_UInt32        hash;
-    FTC_CMapDescRec  desc;
-    FT_UInt          index;
-
-  } FTC_CMapFamilyRec, *FTC_CMapFamily;
-
-
-#define FTC_CMAP_FAMILY( x )         ( (FTC_CMapFamily)( x ) )
-#define FTC_CMAP_FAMILY_MEMORY( x )  FTC_FAMILY( x )->memory
-
-
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
@@ -108,25 +92,40 @@
 
   /* no need for specific finalizer; we use "ftc_node_done" directly */
 
-  /* initialize a new cmap node */
-  FT_CALLBACK_DEF( FT_Error )
-  ftc_cmap_node_init( FTC_CMapNode   cnode,
-                      FTC_CMapQuery  cquery,
+  FT_CALLBACK_DEF( void )
+  ftc_cmap_node_free( FTC_CMapNode   node,
                       FTC_Cache      cache )
   {
-    FT_UInt32  first;
-    FT_UInt    n;
-    FT_UNUSED( cache );
+    FT_Memory  memory = cache->memory;
 
+    FT_FREE( node );
+  }
 
-    first = ( cquery->char_code / FTC_CMAP_INDICES_MAX ) *
-            FTC_CMAP_INDICES_MAX;
 
-    cnode->first = first;
-    for ( n = 0; n < FTC_CMAP_INDICES_MAX; n++ )
-      cnode->indices[n] = FTC_CMAP_UNKNOWN;
+  /* initialize a new cmap node */
+  FT_CALLBACK_DEF( FT_Error )
+  ftc_cmap_node_new( FTC_CMapNode  *anode,
+                     FTC_CMapQuery  query,
+                     FTC_Cache      cache )
+  {
+    FT_Error      error;
+    FT_Memory     memory  = cache->memory;
+    FTC_CMapNode  node;
+    FT_UInt       nn;
 
-    return 0;
+    if ( !FT_NEW( node ) )
+    {
+      node->face_id    = query->face_id;
+      node->cmap_index = query->cmap_index;
+      node->first      = (query->char_code / FTC_CMAP_INDICES_MAX) *
+                         FTC_CMAP_INDICES_MAX;
+
+      for ( nn = 0; nn < FTC_CMAP_INDICES_MAX; nn++ )
+        node->indices[nn] = FTC_CMAP_UNKNOWN;
+    }
+
+    *anode = node;
+    return error;
   }
 
 
@@ -142,188 +141,27 @@
 
   /* compare a cmap node to a given query */
   FT_CALLBACK_DEF( FT_Bool )
-  ftc_cmap_node_compare( FTC_CMapNode   cnode,
-                         FTC_CMapQuery  cquery )
-  {
-    FT_UInt32  offset = (FT_UInt32)( cquery->char_code - cnode->first );
-
-
-    return FT_BOOL( offset < FTC_CMAP_INDICES_MAX );
-  }
-
-
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                    CHARMAP FAMILY                             *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-
-
-  FT_CALLBACK_DEF( FT_Error )
-  ftc_cmap_family_init( FTC_CMapFamily  cfam,
-                        FTC_CMapQuery   cquery,
-                        FTC_Cache       cache )
+  ftc_cmap_node_compare( FTC_CMapNode   node,
+                         FTC_CMapQuery  query )
   {
-    FTC_Manager   manager = cache->manager;
-    FTC_CMapDesc  desc = cquery->desc;
-    FT_UInt32     hash = 0;
-    FT_Error      error;
-    FT_Face       face;
-
-
-    /* setup charmap descriptor */
-    cfam->desc = *desc;
-
-    /* let's see whether the rest is correct too */
-    error = FTC_Manager_Lookup_Face( manager, desc->face_id, &face );
-    if ( !error )
+    if ( node->face_id    == query->face_id    &&
+         node->cmap_index == query->cmap_index )
     {
-      FT_UInt      count = face->num_charmaps;
-      FT_UInt      idx   = count;
-      FT_CharMap*  cur   = face->charmaps;
-
+      FT_UInt32  offset = (FT_UInt32)( query->char_code - node->first );
 
-      switch ( desc->type )
-      {
-      case FTC_CMAP_BY_INDEX:
-        idx  = desc->u.index;
-        hash = idx * 33;
-        break;
-
-      case FTC_CMAP_BY_ENCODING:
-        if ( desc->u.encoding == FT_ENCODING_UNICODE )
-        {
-          /* Since the `interesting' table, pid/eid (3,10), is normally the
-           * last one, we loop backwards.  This looses with type1 fonts with
-           * non-BMP characters (<.0001%), this wins with .ttf with non-BMP
-           * chars (.01% ?), and this is the same about 99.99% of the time!
-           */
-
-          FT_UInt  unicmap_idx = count;  /* some UCS-2 map, if we found it */
-
-
-          cur += count - 1;
-
-          for ( idx = 0; idx < count; idx++, cur-- )
-          {
-            if ( cur[0]->encoding == FT_ENCODING_UNICODE )
-            {
-              unicmap_idx = idx;  /* record we found a Unicode charmap */
-
-              /* XXX If some new encodings to represent UCS-4 are added,
-               *     they should be added here.
-               */
-              if ( ( cur[0]->platform_id == TT_PLATFORM_MICROSOFT &&
-                     cur[0]->encoding_id == TT_MS_ID_UCS_4        )      ||
-                   ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
-                     cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32    )  )
-
-              /* Hurray! We found a UCS-4 charmap.  We can stop the scan! */
-              {
-                idx = count - 1 - idx;
-                goto Found_idx_for_FTC_CMAP_BY_ENCODING;
-              }
-            }
-          }
-
-          /* We do not have any UCS-4 charmap. Sigh.
-           * Let's see if we have some other kind of Unicode charmap, though.
-           */
-          if ( unicmap_idx < count )
-            idx = count - 1 - unicmap_idx;
-        }
-        else
-        {
-          for ( idx = 0; idx < count; idx++, cur++ )
-            if ( cur[0]->encoding == desc->u.encoding )
-              break;
-        }
-
-      Found_idx_for_FTC_CMAP_BY_ENCODING:
-        hash = idx * 67;
-        break;
-
-      case FTC_CMAP_BY_ID:
-        for ( idx = 0; idx < count; idx++, cur++ )
-        {
-          if ( (FT_UInt)cur[0]->platform_id == desc->u.id.platform &&
-               (FT_UInt)cur[0]->encoding_id == desc->u.id.encoding )
-          {
-            hash = ( ( desc->u.id.platform << 8 ) | desc->u.id.encoding ) * 7;
-            break;
-          }
-        }
-        break;
-
-      default:
-        ;
-      }
-
-      if ( idx >= count )
-        goto Bad_Descriptor;
-
-      /* compute hash value, both in family and query */
-      cfam->index               = idx;
-      cfam->hash                = hash ^ FTC_FACE_ID_HASH( desc->face_id );
-      FTC_QUERY( cquery )->hash = FTC_CMAP_HASH( cfam, cquery );
-
-      error = ftc_family_init( FTC_FAMILY( cfam ),
-                               FTC_QUERY( cquery ), cache );
+      return FT_BOOL( offset < FTC_CMAP_INDICES_MAX );
     }
-
-    return error;
-
-  Bad_Descriptor:
-    FT_TRACE1(( "ftp_cmap_family_init: invalid charmap descriptor\n" ));
-    return FTC_Err_Invalid_Argument;
+    return 0;
   }
 
 
   FT_CALLBACK_DEF( FT_Bool )
-  ftc_cmap_family_compare( FTC_CMapFamily  cfam,
-                           FTC_CMapQuery   cquery )
+  ftc_cmap_node_remove_faceid( FTC_CMapNode  node,
+                               FTC_FaceID    face_id )
   {
-    FT_Int  result = 0;
-
-
-    /* first, compare face id and type */
-    if ( cfam->desc.face_id != cquery->desc->face_id ||
-         cfam->desc.type    != cquery->desc->type    )
-      goto Exit;
-
-    switch ( cfam->desc.type )
-    {
-    case FTC_CMAP_BY_INDEX:
-      result = ( cfam->desc.u.index == cquery->desc->u.index );
-      break;
-
-    case FTC_CMAP_BY_ENCODING:
-      result = ( cfam->desc.u.encoding == cquery->desc->u.encoding );
-      break;
-
-    case FTC_CMAP_BY_ID:
-      result = ( cfam->desc.u.id.platform == cquery->desc->u.id.platform &&
-                 cfam->desc.u.id.encoding == cquery->desc->u.id.encoding );
-      break;
-
-    default:
-      ;
-    }
-
-    if ( result )
-    {
-      /* when found, update the 'family' and 'hash' field of the query */
-      FTC_QUERY( cquery )->family = FTC_FAMILY( cfam );
-      FTC_QUERY( cquery )->hash   = FTC_CMAP_HASH( cfam, cquery );
-    }
-
-  Exit:
-    return FT_BOOL( result );
+    return FT_BOOL( node->face_id == face_id );
   }
 
-
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
@@ -334,127 +172,95 @@
 
 
   FT_CALLBACK_TABLE_DEF
-  const FTC_Cache_ClassRec  ftc_cmap_cache_class =
+  const FTC_CacheClassRec  ftc_cmap_cache_class =
   {
+    (FTC_Node_NewFunc)      ftc_cmap_node_new,
+    (FTC_Node_WeightFunc)   ftc_cmap_node_weight,
+    (FTC_Node_CompareFunc)  ftc_cmap_node_compare,
+    (FTC_Node_CompareFunc)  ftc_cmap_node_remove_faceid,
+    (FTC_Node_FreeFunc)     ftc_cmap_node_free,
+
     sizeof ( FTC_CacheRec ),
-    (FTC_Cache_InitFunc) ftc_cache_init,
-    (FTC_Cache_ClearFunc)ftc_cache_clear,
-    (FTC_Cache_DoneFunc) ftc_cache_done,
-
-    sizeof ( FTC_CMapFamilyRec ),
-    (FTC_Family_InitFunc)   ftc_cmap_family_init,
-    (FTC_Family_CompareFunc)ftc_cmap_family_compare,
-    (FTC_Family_DoneFunc)   ftc_family_done,
-
-    sizeof ( FTC_CMapNodeRec ),
-    (FTC_Node_InitFunc)   ftc_cmap_node_init,
-    (FTC_Node_WeightFunc) ftc_cmap_node_weight,
-    (FTC_Node_CompareFunc)ftc_cmap_node_compare,
-    (FTC_Node_DoneFunc)   ftc_node_done
+    (FTC_Cache_InitFunc) FTC_Cache_Init,
+    (FTC_Cache_DoneFunc) FTC_Cache_Done,
   };
 
-
   /* documentation is in ftccmap.h */
 
   FT_EXPORT_DEF( FT_Error )
   FTC_CMapCache_New( FTC_Manager     manager,
                      FTC_CMapCache  *acache )
   {
-    return FTC_Manager_Register_Cache(
-             manager,
-             (FTC_Cache_Class)&ftc_cmap_cache_class,
-             FTC_CACHE_P( acache ) );
+    return FTC_Manager_RegisterCache( manager,
+                                      & ftc_cmap_cache_class,
+                                      FTC_CACHE_P( acache ) );
   }
-
-
-#ifdef FTC_CACHE_USE_INLINE
-
-#define GEN_CACHE_FAMILY_COMPARE( f, q, c ) \
-          ftc_cmap_family_compare( (FTC_CMapFamily)(f), (FTC_CMapQuery)(q) )
-
-#define GEN_CACHE_NODE_COMPARE( n, q, c ) \
-          ftc_cmap_node_compare( (FTC_CMapNode)(n), (FTC_CMapQuery)(q) )
-
-#define GEN_CACHE_LOOKUP  ftc_cmap_cache_lookup
-
-#include "ftccache.i"
-
-#else  /* !FTC_CACHE_USE_INLINE */
-
-#define ftc_cmap_cache_lookup  ftc_cache_lookup
-
-#endif /* !FTC_CACHE_USE_INLINE */
-
-
   /* documentation is in ftccmap.h */
 
   FT_EXPORT_DEF( FT_UInt )
-  FTC_CMapCache_Lookup( FTC_CMapCache  cache,
-                        FTC_CMapDesc   desc,
+  FTC_CMapCache_Lookup( FTC_CMapCache  cmap_cache,
+                        FTC_FaceID     face_id,
+                        FT_UInt        cmap_index,
                         FT_UInt32      char_code )
   {
-    FTC_CMapQueryRec  cquery;
+    FTC_Cache         cache = FTC_CACHE( cmap_cache );
+    FTC_CMapQueryRec  query;
     FTC_CMapNode      node;
     FT_Error          error;
     FT_UInt           gindex = 0;
+    FT_UInt32         hash;
 
 
-    if ( !cache || !desc )
+    if ( !cache )
     {
       FT_ERROR(( "FTC_CMapCache_Lookup: bad arguments, returning 0!\n" ));
       return 0;
     }
 
-    cquery.desc      = desc;
-    cquery.char_code = char_code;
+    query.face_id    = face_id;
+    query.cmap_index = cmap_index;
+    query.char_code  = char_code;
 
-    error = ftc_cmap_cache_lookup( FTC_CACHE( cache ),
-                                   FTC_QUERY( &cquery ),
-                                   (FTC_Node*)&node );
-    if ( !error )
-    {
-      FT_UInt  offset = (FT_UInt)( char_code - node->first );
+    hash = FTC_CMAP_HASH( face_id, cmap_index, char_code );
 
+    error = FTC_Cache_Lookup( cache, hash, &query, (FTC_Node*) &node );
+    if ( error )
+      goto Exit;
 
-      FT_ASSERT( offset < FTC_CMAP_INDICES_MAX );
-
-      gindex = node->indices[offset];
-      if ( gindex == FTC_CMAP_UNKNOWN )
-      {
-        FT_Face  face;
+    FT_ASSERT( (FT_UInt)( char_code - node->first ) < FTC_CMAP_INDICES_MAX );
 
+    gindex = node->indices[ char_code - node->first ];
+    if ( gindex == FTC_CMAP_UNKNOWN )
+    {
+      FT_Face     face;
 
-        /* we need to use FT_Get_Char_Index */
-        gindex = 0;
+      gindex = 0;
 
-        error = FTC_Manager_Lookup_Face( FTC_CACHE(cache)->manager,
-                                         desc->face_id,
-                                         &face );
-        if ( !error )
-        {
-          FT_CharMap  old, cmap  = NULL;
-          FT_UInt     cmap_index;
+      error = FTC_Manager_LookupFace( cache->manager, node->face_id, &face );
+      if ( error )
+        goto Exit;
 
+      if ( (FT_UInt)cmap_index < (FT_UInt)face->num_charmaps )
+      {
+        FT_CharMap  old, cmap  = NULL;
 
-          /* save old charmap, select new one */
-          old        = face->charmap;
-          cmap_index = FTC_CMAP_FAMILY( FTC_QUERY( &cquery )->family )->index;
-          cmap       = face->charmaps[cmap_index];
+        old  = face->charmap;
+        cmap = face->charmaps[ cmap_index ];
 
+        if (old != cmap)
           FT_Set_Charmap( face, cmap );
 
-          /* perform lookup */
-          gindex                = FT_Get_Char_Index( face, char_code );
-          node->indices[offset] = (FT_UInt16)gindex;
+        gindex = FT_Get_Char_Index( face, char_code );
 
-          /* restore old charmap */
+        if (old != cmap)
           FT_Set_Charmap( face, old );
-        }
       }
+
+      node->indices[ char_code - node->first ] = gindex;
     }
 
+  Exit:
     return gindex;
   }
 
-
 /* END */
diff --git a/src/cache/ftcglyph.c b/src/cache/ftcglyph.c
index aa21228..f877e9b 100644
--- a/src/cache/ftcglyph.c
+++ b/src/cache/ftcglyph.c
@@ -20,7 +20,6 @@
 #include FT_CACHE_H
 #include FT_CACHE_INTERNAL_GLYPH_H
 #include FT_ERRORS_H
-#include FT_LIST_H
 #include FT_INTERNAL_OBJECTS_H
 #include FT_INTERNAL_DEBUG_H
 
@@ -29,45 +28,45 @@
 
   /* create a new chunk node, setting its cache index and ref count */
   FT_EXPORT_DEF( void )
-  ftc_glyph_node_init( FTC_GlyphNode     gnode,
-                       FT_UInt           gindex,
-                       FTC_GlyphFamily   gfam )
+  FTC_GNode_Init( FTC_GNode   gnode,
+                  FT_UInt     gindex,
+                  FTC_Family  family )
   {
-    FT_UInt  len;
-    FT_UInt  start = FTC_GLYPH_FAMILY_START( gfam, gindex );
-
+    gnode->family = family;
+    gnode->gindex = gindex;
+    family->num_nodes++;
+  }
 
-    gnode->item_start = (FT_UShort)start;
 
-    len = gfam->item_total - start;
-    if ( len > gfam->item_count )
-      len = gfam->item_count;
+  FT_EXPORT_DEF( void )
+  FTC_GNode_UnselectFamily( FTC_GNode   gnode,
+                            FTC_Cache   cache )
+  {
+    FTC_Family  family = gnode->family;
 
-    gnode->item_count = (FT_UShort)len;
-    gfam->family.num_nodes++;
+    gnode->family = NULL;
+    if ( family && --family->num_nodes <= 0 )
+      FTC_MruList_Remove( & FTC_GCACHE(cache)->families, (FTC_MruNode)family );
   }
 
 
   FT_EXPORT_DEF( void )
-  ftc_glyph_node_done( FTC_GlyphNode  gnode,
-                       FTC_Cache      cache )
+  FTC_GNode_Done( FTC_GNode  gnode,
+                  FTC_Cache  cache )
   {
     /* finalize the node */
-    gnode->item_count = 0;
-    gnode->item_start = 0;
+    gnode->gindex = 0;
 
-    ftc_node_done( FTC_NODE( gnode ), cache );
+    FTC_GNode_UnselectFamily( gnode, cache );
   }
 
 
   FT_EXPORT_DEF( FT_Bool )
-  ftc_glyph_node_compare( FTC_GlyphNode   gnode,
-                          FTC_GlyphQuery  gquery )
+  FTC_GNode_Compare( FTC_GNode   gnode,
+                     FTC_GQuery  gquery )
   {
-    FT_UInt  start = (FT_UInt)gnode->item_start;
-    FT_UInt  count = (FT_UInt)gnode->item_count;
-
-    return FT_BOOL( (FT_UInt)( gquery->gindex - start ) < count );
+    return FT_BOOL(  gnode->family == gquery->family &&
+                     gnode->gindex == gquery->gindex );
   }
 
 
@@ -79,36 +78,72 @@
   /*************************************************************************/
   /*************************************************************************/
 
+  FT_EXPORT_DEF( void )
+  ftc_family_init( FTC_Family  family,
+                   FTC_Cache   cache )
+  {
+    FTC_GCacheClass  clazz = FTC_CACHE__GCACHE_CLASS(cache);
+
+    family->clazz     = clazz->family_class;
+    family->num_nodes = 0;
+  }
+
 
   FT_EXPORT_DEF( FT_Error )
-  ftc_glyph_family_init( FTC_GlyphFamily  gfam,
-                         FT_UInt32        hash,
-                         FT_UInt          item_count,
-                         FT_UInt          item_total,
-                         FTC_GlyphQuery   gquery,
-                         FTC_Cache        cache )
+  FTC_GCache_Init( FTC_GCache  cache )
   {
-    FT_Error  error;
-
+    FT_Error error;
 
-    error = ftc_family_init( FTC_FAMILY( gfam ), FTC_QUERY( gquery ), cache );
+    error = FTC_Cache_Init( FTC_CACHE(cache) );
     if ( !error )
     {
-      gfam->hash       = hash;
-      gfam->item_total = item_total;
-      gfam->item_count = item_count;
-      
-      FTC_GLYPH_FAMILY_FOUND( gfam, gquery );
-    }
+      FTC_GCacheClass   clazz = (FTC_GCacheClass) FTC_CACHE(cache)->org_class;
 
+      FTC_MruList_Init( &cache->families,
+                        clazz->family_class,
+                        0,  /* no maximum here !! */
+                        cache,
+                        FTC_CACHE(cache)->memory );
+    }
     return error;
   }
 
 
   FT_EXPORT_DEF( void )
-  ftc_glyph_family_done( FTC_GlyphFamily  gfam )
+  FTC_GCache_Done( FTC_GCache  cache )
+  {
+    FTC_Cache_Done( (FTC_Cache)cache );
+    FTC_MruList_Done( &cache->families );
+  }
+
+
+  FT_EXPORT_DEF( FT_Error )
+  FTC_GCache_New( FTC_Manager       manager,
+                  FTC_GCacheClass   clazz,
+                  FTC_GCache       *acache )
   {
-    ftc_family_done( FTC_FAMILY( gfam ) );
+    return FTC_Manager_RegisterCache( manager, (FTC_CacheClass) clazz,
+                                      (FTC_Cache*) acache );
+  }
+
+
+  FT_EXPORT_DEF( FT_Error )
+  FTC_GCache_Lookup( FTC_GCache   cache,
+                     FT_UInt32    hash,
+                     FT_UInt      gindex,
+                     FTC_GQuery   query,
+                     FTC_Node    *anode )
+  {
+    FT_Error  error;
+
+    query->gindex = gindex;
+
+    error = FTC_MruList_Lookup( &cache->families, query,
+                                (FTC_MruNode*) &query->family );
+    if ( !error )
+      error = FTC_Cache_Lookup( FTC_CACHE(cache), hash, query, anode );
+
+    return error;
   }
 
 
diff --git a/src/cache/ftcimage.c b/src/cache/ftcimage.c
index fa1b6ac..574ef78 100644
--- a/src/cache/ftcimage.c
+++ b/src/cache/ftcimage.c
@@ -18,133 +18,60 @@
 
 #include <ft2build.h>
 #include FT_CACHE_H
-#include FT_CACHE_IMAGE_H
-#include FT_CACHE_INTERNAL_GLYPH_H
+#include FT_CACHE_INTERNAL_IMAGE_H
 #include FT_INTERNAL_MEMORY_H
 
 #include "ftcerror.h"
 
 
-  /* the FT_Glyph image node type */
-  typedef struct  FTC_ImageNodeRec_
-  {
-    FTC_GlyphNodeRec  gnode;
-    FT_Glyph          glyph;
-
-  } FTC_ImageNodeRec, *FTC_ImageNode;
-
-
-#define FTC_IMAGE_NODE( x )         ( (FTC_ImageNode)( x ) )
-#define FTC_IMAGE_NODE_GINDEX( x )  FTC_GLYPH_NODE_GINDEX( x )
-
-
-  /* the glyph image query */
-  typedef struct  FTC_ImageQueryRec_
-  {
-    FTC_GlyphQueryRec  gquery;
-    FTC_ImageTypeRec   type;
-
-  } FTC_ImageQueryRec, *FTC_ImageQuery;
-
-
-#define FTC_IMAGE_QUERY( x )  ( (FTC_ImageQuery)( x ) )
-
-
-  /* the glyph image set type */
-  typedef struct  FTC_ImageFamilyRec_
-  {
-    FTC_GlyphFamilyRec  gfam;
-    FTC_ImageTypeRec    type;
-
-  } FTC_ImageFamilyRec, *FTC_ImageFamily;
-
-
-#define FTC_IMAGE_FAMILY( x )         ( (FTC_ImageFamily)( x ) )
-#define FTC_IMAGE_FAMILY_MEMORY( x )  FTC_GLYPH_FAMILY_MEMORY( &(x)->gfam )
-
-
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                    GLYPH IMAGE NODES                          *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-
-
   /* finalize a given glyph image node */
-  FT_CALLBACK_DEF( void )
-  ftc_image_node_done( FTC_ImageNode  inode,
-                       FTC_Cache      cache )
+  FT_EXPORT_DEF( void )
+  FTC_INode_Free( FTC_INode  inode,
+                  FTC_Cache  cache )
   {
+    FT_Memory  memory = cache->memory;
+
     if ( inode->glyph )
     {
       FT_Done_Glyph( inode->glyph );
       inode->glyph = NULL;
     }
 
-    ftc_glyph_node_done( FTC_GLYPH_NODE( inode ), cache );
+    FTC_GNode_Done( FTC_GNODE( inode ), cache );
+    FT_FREE( inode );
   }
 
 
   /* initialize a new glyph image node */
-  FT_CALLBACK_DEF( FT_Error )
-  ftc_image_node_init( FTC_ImageNode   inode,
-                       FTC_GlyphQuery  gquery,
-                       FTC_Cache       cache )
+  FT_EXPORT_DEF( FT_Error )
+  FTC_INode_New( FTC_INode   *pinode,
+                 FTC_GQuery   gquery,
+                 FTC_Cache    cache )
   {
-    FTC_ImageFamily  ifam = FTC_IMAGE_FAMILY( gquery->query.family );
-    FT_Error         error;
-    FT_Face          face;
-    FT_Size          size;
+    FT_Memory  memory = cache->memory;
+    FT_Error   error;
+    FTC_INode  inode;
 
-
-    /* initialize its inner fields */
-    ftc_glyph_node_init( FTC_GLYPH_NODE( inode ),
-                         gquery->gindex,
-                         FTC_GLYPH_FAMILY( ifam ) );
-
-    /* we will now load the glyph image */
-    error = FTC_Manager_Lookup_Size( FTC_FAMILY( ifam )->cache->manager,
-                                     &ifam->type.font,
-                                     &face, &size );
-    if ( !error )
+    if ( !FT_NEW( inode ) )
     {
-      FT_UInt  gindex = FTC_GLYPH_NODE_GINDEX( inode );
+      FTC_GNode         gnode  = FTC_GNODE( inode );
+      FTC_Family        family = gquery->family;
+      FT_UInt           gindex = gquery->gindex;
+      FTC_IFamilyClass  clazz  = FTC_CACHE__IFAMILY_CLASS( cache );
 
+      /* initialize its inner fields */
+      FTC_GNode_Init( gnode, gindex, family );
 
-      error = FT_Load_Glyph( face, gindex, ifam->type.flags );
-      if ( !error )
-      {
-        if ( face->glyph->format == FT_GLYPH_FORMAT_BITMAP  ||
-             face->glyph->format == FT_GLYPH_FORMAT_OUTLINE )
-        {
-          /* ok, copy it */
-          FT_Glyph  glyph;
-
-
-          error = FT_Get_Glyph( face->glyph, &glyph );
-          if ( !error )
-          {
-            inode->glyph = glyph;
-            goto Exit;
-          }
-        }
-        else
-          error = FTC_Err_Invalid_Argument;
-      }
+      /* we will now load the glyph image */
+      error = clazz->family_load_glyph( family, gindex, cache, &inode->glyph );
     }
-
-    /* in case of error */
-    ftc_glyph_node_done( FTC_GLYPH_NODE(inode), cache );
-
-  Exit:
+    *pinode = inode;
     return error;
   }
 
 
-  FT_CALLBACK_DEF( FT_ULong )
-  ftc_image_node_weight( FTC_ImageNode  inode )
+  FT_EXPORT_DEF( FT_ULong )
+  FTC_INode_Weight( FTC_INode  inode )
   {
     FT_ULong  size  = 0;
     FT_Glyph  glyph = inode->glyph;
@@ -185,215 +112,4 @@
   }
 
 
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                    GLYPH IMAGE SETS                           *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-
-
-  FT_CALLBACK_DEF( FT_Error )
-  ftc_image_family_init( FTC_ImageFamily  ifam,
-                         FTC_ImageQuery   iquery,
-                         FTC_Cache        cache )
-  {
-    FTC_Manager  manager = cache->manager;
-    FT_Error     error;
-    FT_Face      face;
-
-
-    ifam->type = iquery->type;
-
-    /* we need to compute "iquery.item_total" now */
-    error = FTC_Manager_Lookup_Face( manager,
-                                     iquery->type.font.face_id,
-                                     &face );
-    if ( !error )
-    {
-      error = ftc_glyph_family_init( FTC_GLYPH_FAMILY( ifam ),
-                                     FTC_IMAGE_TYPE_HASH( &ifam->type ),
-                                     1,
-                                     face->num_glyphs,
-                                     FTC_GLYPH_QUERY( iquery ),
-                                     cache );
-    }
-
-    return error;
-  }
-
-
-  FT_CALLBACK_DEF( FT_Bool )
-  ftc_image_family_compare( FTC_ImageFamily  ifam,
-                            FTC_ImageQuery   iquery )
-  {
-    FT_Bool  result;
-
-
-    result = FT_BOOL( FTC_IMAGE_TYPE_COMPARE( &ifam->type, &iquery->type ) );
-    if ( result )
-      FTC_GLYPH_FAMILY_FOUND( ifam, iquery );
-
-    return result;
-  }
-
-
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                    GLYPH IMAGE CACHE                          *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-
-
-
-  FT_CALLBACK_TABLE_DEF
-  const FTC_Cache_ClassRec  ftc_image_cache_class =
-  {
-    sizeof ( FTC_CacheRec ),
-    (FTC_Cache_InitFunc) ftc_cache_init,
-    (FTC_Cache_ClearFunc)ftc_cache_clear,
-    (FTC_Cache_DoneFunc) ftc_cache_done,
-
-    sizeof ( FTC_ImageFamilyRec ),
-    (FTC_Family_InitFunc)   ftc_image_family_init,
-    (FTC_Family_CompareFunc)ftc_image_family_compare,
-    (FTC_Family_DoneFunc)   ftc_glyph_family_done,
-
-    sizeof ( FTC_ImageNodeRec ),
-    (FTC_Node_InitFunc)   ftc_image_node_init,
-    (FTC_Node_WeightFunc) ftc_image_node_weight,
-    (FTC_Node_CompareFunc)ftc_glyph_node_compare,
-    (FTC_Node_DoneFunc)   ftc_image_node_done
-  };
-
-
-  /* documentation is in ftcimage.h */
-
-  FT_EXPORT_DEF( FT_Error )
-  FTC_ImageCache_New( FTC_Manager      manager,
-                      FTC_ImageCache  *acache )
-  {
-    return FTC_Manager_Register_Cache(
-             manager,
-             (FTC_Cache_Class)&ftc_image_cache_class,
-             FTC_CACHE_P( acache ) );
-  }
-
-
-  /* documentation is in ftcimage.h */
-
-  FT_EXPORT_DEF( FT_Error )
-  FTC_ImageCache_Lookup( FTC_ImageCache  cache,
-                         FTC_ImageType   type,
-                         FT_UInt         gindex,
-                         FT_Glyph       *aglyph,
-                         FTC_Node       *anode )
-  {
-    FTC_ImageQueryRec  iquery;
-    FTC_ImageNode      node;
-    FT_Error           error;
-
-
-    /* some argument checks are delayed to ftc_cache_lookup */
-    if ( !aglyph )
-      return FTC_Err_Invalid_Argument;
-
-    if ( anode )
-      *anode  = NULL;
-
-    iquery.gquery.gindex = gindex;
-    iquery.type          = *type;
-
-    error = ftc_cache_lookup( FTC_CACHE( cache ),
-                              FTC_QUERY( &iquery ),
-                              (FTC_Node*)&node );
-    if ( !error )
-    {
-      *aglyph = node->glyph;
-
-      if ( anode )
-      {
-        *anode = (FTC_Node)node;
-        FTC_NODE( node )->ref_count++;
-      }
-    }
-
-    return error;
-  }
-
-
-  /* backwards-compatibility functions */
-
-  FT_EXPORT_DEF( FT_Error )
-  FTC_Image_Cache_New( FTC_Manager       manager,
-                       FTC_Image_Cache  *acache )
-  {
-    return FTC_ImageCache_New( manager, (FTC_ImageCache*)acache );
-  }
-
-
-  FT_EXPORT_DEF( FT_Error )
-  FTC_Image_Cache_Lookup( FTC_Image_Cache  icache,
-                          FTC_Image_Desc*  desc,
-                          FT_UInt          gindex,
-                          FT_Glyph        *aglyph )
-  {
-    FTC_ImageTypeRec  type0;
-
-
-    if ( !desc )
-      return FTC_Err_Invalid_Argument;
-
-    type0.font = desc->font;
-
-    /* convert image type flags to load flags */
-    {
-      FT_UInt  load_flags = FT_LOAD_DEFAULT;
-      FT_UInt  type       = desc->image_type;
-
-
-      /* determine load flags, depending on the font description's */
-      /* image type                                                */
-
-      if ( ftc_image_format( type ) == ftc_image_format_bitmap )
-      {
-        if ( type & ftc_image_flag_monochrome )
-          load_flags |= FT_LOAD_MONOCHROME;
-
-        /* disable embedded bitmaps loading if necessary */
-        if ( type & ftc_image_flag_no_sbits )
-          load_flags |= FT_LOAD_NO_BITMAP;
-      }
-      else
-      {
-        /* we want an outline, don't load embedded bitmaps */
-        load_flags |= FT_LOAD_NO_BITMAP;
-
-        if ( type & ftc_image_flag_unscaled )
-          load_flags |= FT_LOAD_NO_SCALE;
-      }
-
-      /* always render glyphs to bitmaps */
-      load_flags |= FT_LOAD_RENDER;
-
-      if ( type & ftc_image_flag_unhinted )
-        load_flags |= FT_LOAD_NO_HINTING;
-
-      if ( type & ftc_image_flag_autohinted )
-        load_flags |= FT_LOAD_FORCE_AUTOHINT;
-
-      type0.flags = load_flags;
-    }
-
-    return FTC_ImageCache_Lookup( (FTC_ImageCache)icache,
-                                   &type0,
-                                   gindex,
-                                   aglyph,
-                                   NULL );
-  }
-
-
 /* END */
diff --git a/src/cache/ftcmanag.c b/src/cache/ftcmanag.c
index 7cdb8f9..388df25 100644
--- a/src/cache/ftcmanag.c
+++ b/src/cache/ftcmanag.c
@@ -18,8 +18,7 @@
 
 #include <ft2build.h>
 #include FT_CACHE_H
-#include FT_CACHE_MANAGER_H
-#include FT_CACHE_INTERNAL_LRU_H
+#include FT_CACHE_INTERNAL_MANAGER_H
 #include FT_INTERNAL_OBJECTS_H
 #include FT_INTERNAL_DEBUG_H
 #include FT_SIZES_H
@@ -33,124 +32,135 @@
 #define FTC_LRU_GET_MANAGER( lru )  ( (FTC_Manager)(lru)->user_data )
 
 
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                    FACE LRU IMPLEMENTATION                    *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
+  static FT_Error
+  ftc_scaler_lookup_size( FTC_Manager    manager,
+                          FTC_Scaler     scaler,
+                          FT_Size       *asize )
+  {
+    FT_Face   face;
+    FT_Size   size = NULL;
+    FT_Error  error;
 
-  typedef struct FTC_FaceNodeRec_*  FTC_FaceNode;
-  typedef struct FTC_SizeNodeRec_*  FTC_SizeNode;
+    error = FTC_Manager_LookupFace( manager, scaler->face_id, &face );
+    if ( error ) goto Exit;
 
+    error = FT_New_Size( face, &size );
+    if ( error ) goto Exit;
 
-  typedef struct  FTC_FaceNodeRec_
-  {
-    FT_LruNodeRec  lru;
-    FT_Face        face;
+    FT_Activate_Size( size );
 
-  } FTC_FaceNodeRec;
+    if ( scaler->pixel )
+      error = FT_Set_Pixel_Sizes( face, scaler->width, scaler->height );
+    else
+      error = FT_Set_Char_Size( face, scaler->width, scaler->height,
+                                scaler->x_res, scaler->y_res );
+    if ( error )
+    {
+      FT_Done_Size( size );
+      size = NULL;
+    }
 
+  Exit:
+    *asize = size;
+    return error;
+  }
 
-  typedef struct  FTC_SizeNodeRec_
+
+  typedef struct FTC_SizeNodeRec_
   {
-    FT_LruNodeRec  lru;
-    FT_Size        size;
+    FTC_MruNodeRec    node;
+    FT_Size           size;
+    FTC_ScalerRec     scaler;
 
-  } FTC_SizeNodeRec;
+  } FTC_SizeNodeRec, *FTC_SizeNode;
 
 
-  FT_CALLBACK_DEF( FT_Error )
-  ftc_face_node_init( FTC_FaceNode  node,
-                      FTC_FaceID    face_id,
-                      FTC_Manager   manager )
+  FT_CALLBACK_DEF( void )
+  ftc_size_node_done( FTC_SizeNode  node )
   {
-    FT_Error  error;
-
-
-    error = manager->request_face( face_id,
-                                   manager->library,
-                                   manager->request_data,
-                                   &node->face );
-    if ( !error )
-    {
-      /* destroy initial size object; it will be re-created later */
-      if ( node->face->size )
-        FT_Done_Size( node->face->size );
-    }
+    FT_Size  size = node->size;
 
-    return error;
+    if ( size )
+      FT_Done_Size( size );
   }
 
 
-  /* helper function for ftc_face_node_done() */
   FT_CALLBACK_DEF( FT_Bool )
-  ftc_size_node_select( FTC_SizeNode  node,
-                        FT_Face       face )
+  ftc_size_node_compare( FTC_SizeNode  node,
+                         FTC_Scaler    scaler )
   {
-    return FT_BOOL( node->size->face == face );
+    FTC_Scaler  scaler0 = &node->scaler;
+
+    return FTC_SCALER_COMPARE( scaler0, scaler );
   }
 
 
-  FT_CALLBACK_DEF( void )
-  ftc_face_node_done( FTC_FaceNode  node,
-                      FTC_Manager   manager )
+
+  FT_CALLBACK_DEF( FT_Error )
+  ftc_size_node_init( FTC_SizeNode   node,
+                      FTC_Scaler     scaler,
+                      FTC_Manager    manager )
   {
-    FT_Face  face    = node->face;
+    node->scaler = scaler[0];
+
+    return ftc_scaler_lookup_size( manager, scaler, &node->size );
+  }
 
 
-    /* we must begin by removing all sizes for the target face */
-    /* from the manager's list                                 */
-    FT_LruList_Remove_Selection( manager->sizes_list,
-                                 (FT_LruNode_SelectFunc)ftc_size_node_select,
-                                 face );
+  FT_CALLBACK_DEF( FT_Error )
+  ftc_size_node_reset( FTC_SizeNode       node,
+                       FTC_Scaler         scaler,
+                       FTC_Manager        manager )
+  {
+    FT_Done_Size( node->size );
 
-    /* all right, we can discard the face now */
-    FT_Done_Face( face );
-    node->face = NULL;
+    node->scaler = scaler[0];
+
+    return ftc_scaler_lookup_size( manager, scaler, &node->size );
   }
 
 
-  FT_CALLBACK_TABLE_DEF
-  const FT_LruList_ClassRec  ftc_face_list_class =
+  static const FTC_MruListClassRec  ftc_size_list_class =
   {
-    sizeof ( FT_LruListRec ),
-    (FT_LruList_InitFunc)0,
-    (FT_LruList_DoneFunc)0,
-
-    sizeof ( FTC_FaceNodeRec ),
-    (FT_LruNode_InitFunc)   ftc_face_node_init,
-    (FT_LruNode_DoneFunc)   ftc_face_node_done,
-    (FT_LruNode_FlushFunc)  0,  /* no flushing needed                      */
-    (FT_LruNode_CompareFunc)0,  /* direct comparison of FTC_FaceID handles */
+    sizeof( FTC_SizeNodeRec ),
+    (FTC_MruNode_CompareFunc)  ftc_size_node_compare,
+    (FTC_MruNode_InitFunc)     ftc_size_node_init,
+    (FTC_MruNode_ResetFunc)    ftc_size_node_reset,
+    (FTC_MruNode_DoneFunc)     ftc_size_node_done
   };
 
 
-  /* documentation is in ftcache.h */
+ /* helper function used by ftc_face_node_done */
+  static FT_Bool
+  ftc_size_node_compare_faceid( FTC_SizeNode  node,
+                                FTC_FaceID    face_id )
+  {
+    return FT_BOOL( node->scaler.face_id == face_id );
+  }
+
 
   FT_EXPORT_DEF( FT_Error )
-  FTC_Manager_Lookup_Face( FTC_Manager  manager,
-                           FTC_FaceID   face_id,
-                           FT_Face     *aface )
+  FTC_Manager_LookupSize( FTC_Manager    manager,
+                          FTC_Scaler     scaler,
+                          FT_Size       *asize )
   {
     FT_Error      error;
-    FTC_FaceNode  node;
+    FTC_SizeNode  node;
 
 
-    if ( aface == NULL )
+    if ( asize == NULL )
       return FTC_Err_Bad_Argument;
 
-    *aface = NULL;
+    *asize = NULL;
 
     if ( !manager )
       return FTC_Err_Invalid_Cache_Handle;
 
-    error = FT_LruList_Lookup( manager->faces_list,
-                               (FT_LruKey)face_id,
-                               (FT_LruNode*)&node );
+    error = FTC_MruList_Lookup( &manager->sizes,
+                                scaler,
+                                (FTC_MruNode*) &node );
     if ( !error )
-      *aface = node->face;
+      *asize = node->size;
 
     return error;
   }
@@ -159,278 +169,116 @@
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
-  /*****                      SIZES LRU IMPLEMENTATION                 *****/
+  /*****                    FACE MRU IMPLEMENTATION                    *****/
   /*****                                                               *****/
   /*************************************************************************/
   /*************************************************************************/
 
-
-  typedef struct  FTC_SizeQueryRec_
+  typedef struct  FTC_FaceNodeRec_
   {
-    FT_Face  face;
-    FT_UInt  width;
-    FT_UInt  height;
+    FTC_MruNodeRec  node;
+    FTC_FaceID      face_id;
+    FT_Face         face;
+
+  } FTC_FaceNodeRec, *FTC_FaceNode;
 
-  } FTC_SizeQueryRec, *FTC_SizeQuery;
 
 
   FT_CALLBACK_DEF( FT_Error )
-  ftc_size_node_init( FTC_SizeNode   node,
-                      FTC_SizeQuery  query )
+  ftc_face_node_init( FTC_FaceNode  node,
+                      FTC_FaceID    face_id,
+                      FTC_Manager   manager )
   {
-    FT_Face   face = query->face;
-    FT_Size   size;
-    FT_Error  error;
+    FT_Error      error;
 
+    node->face_id = face_id;
 
-    node->size = NULL;
-    error = FT_New_Size( face, &size );
+    error = manager->request_face( face_id,
+                                   manager->library,
+                                   manager->request_data,
+                                   &node->face );
     if ( !error )
     {
-      FT_Activate_Size( size );
-      error = FT_Set_Pixel_Sizes( query->face,
-                                  query->width,
-                                  query->height );
-      if ( error )
-        FT_Done_Size( size );
-      else
-        node->size = size;
+      /* destroy initial size object; it will be re-created later */
+      if ( node->face->size )
+        FT_Done_Size( node->face->size );
     }
     return error;
   }
 
 
   FT_CALLBACK_DEF( void )
-  ftc_size_node_done( FTC_SizeNode  node )
+  ftc_face_node_done( FTC_FaceNode  node,
+                      FTC_Manager   manager )
   {
-    if ( node->size )
-    {
-      FT_Done_Size( node->size );
-      node->size = NULL;
-    }
-  }
+    FT_Memory  memory = manager->memory;
 
 
-  FT_CALLBACK_DEF( FT_Error )
-  ftc_size_node_flush( FTC_SizeNode   node,
-                       FTC_SizeQuery  query )
-  {
-    FT_Size   size = node->size;
-    FT_Error  error;
+    /* we must begin by removing all scalers for the target face */
+    /* from the manager's list                                   */
+    FTC_MruList_RemoveSelection(
+          & manager->sizes,
+          (FTC_MruNode_CompareFunc) ftc_size_node_compare_faceid,
+          node->face_id );
 
+    /* all right, we can discard the face now */
+    FT_Done_Face( node->face );
+    node->face    = NULL;
+    node->face_id = NULL;
 
-    if ( size->face == query->face )
-    {
-      FT_Activate_Size( size );
-      error = FT_Set_Pixel_Sizes( query->face, query->width, query->height );
-      if ( error )
-      {
-        FT_Done_Size( size );
-        node->size = NULL;
-      }
-    }
-    else
-    {
-      FT_Done_Size( size );
-      node->size = NULL;
-
-      error = ftc_size_node_init( node, query );
-    }
-    return error;
+    FT_FREE( node );
   }
 
 
   FT_CALLBACK_DEF( FT_Bool )
-  ftc_size_node_compare( FTC_SizeNode   node,
-                         FTC_SizeQuery  query )
+  ftc_face_node_compare( FTC_FaceNode  node,
+                         FTC_FaceID    face_id )
   {
-    FT_Size  size = node->size;
-
-
-    return FT_BOOL( size->face                    == query->face   &&
-                    (FT_UInt)size->metrics.x_ppem == query->width  &&
-                    (FT_UInt)size->metrics.y_ppem == query->height );
+    return FT_BOOL( node->face_id == face_id );
   }
 
 
-  FT_CALLBACK_TABLE_DEF
-  const FT_LruList_ClassRec  ftc_size_list_class =
-  {
-    sizeof ( FT_LruListRec ),
-    (FT_LruList_InitFunc)0,
-    (FT_LruList_DoneFunc)0,
-
-    sizeof ( FTC_SizeNodeRec ),
-    (FT_LruNode_InitFunc)   ftc_size_node_init,
-    (FT_LruNode_DoneFunc)   ftc_size_node_done,
-    (FT_LruNode_FlushFunc)  ftc_size_node_flush,
-    (FT_LruNode_CompareFunc)ftc_size_node_compare
-  };
-
-
-  /* documentation is in ftcache.h */
-
-  FT_EXPORT_DEF( FT_Error )
-  FTC_Manager_Lookup_Size( FTC_Manager  manager,
-                           FTC_Font     font,
-                           FT_Face     *aface,
-                           FT_Size     *asize )
+  static const FTC_MruListClassRec  ftc_face_list_class =
   {
-    FT_Error  error;
-
-
-    /* check for valid `manager' delayed to FTC_Manager_Lookup_Face() */
-    if ( aface )
-      *aface = 0;
+    sizeof( FTC_FaceNodeRec),
 
-    if ( asize )
-      *asize = 0;
-
-    error = FTC_Manager_Lookup_Face( manager, font->face_id, aface );
-    if ( !error )
-    {
-      FTC_SizeQueryRec  query;
-      FTC_SizeNode      node;
-
-
-      query.face   = *aface;
-      query.width  = font->pix_width;
-      query.height = font->pix_height;
-
-      error = FT_LruList_Lookup( manager->sizes_list,
-                                 (FT_LruKey)&query,
-                                 (FT_LruNode*)&node );
-      if ( !error )
-      {
-        /* select the size as the current one for this face */
-        FT_Activate_Size( node->size );
-
-        if ( asize )
-          *asize = node->size;
-      }
-    }
-
-    return error;
-  }
-
-
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                    SET TABLE MANAGEMENT                       *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-
-  static void
-  ftc_family_table_init( FTC_FamilyTable  table )
-  {
-    table->count   = 0;
-    table->size    = 0;
-    table->entries = NULL;
-    table->free    = FTC_FAMILY_ENTRY_NONE;
-  }
+    (FTC_MruNode_CompareFunc) ftc_face_node_compare,
+    (FTC_MruNode_InitFunc)    ftc_face_node_init,
+    (FTC_MruNode_ResetFunc)   NULL,
+    (FTC_MruNode_DoneFunc)    ftc_face_node_done
+  };
 
 
-  static void
-  ftc_family_table_done( FTC_FamilyTable  table,
-                         FT_Memory        memory )
-  {
-    FT_FREE( table->entries );
-    table->free  = 0;
-    table->count = 0;
-    table->size  = 0;
-  }
 
+  /* documentation is in ftcache.h */
 
   FT_EXPORT_DEF( FT_Error )
-  ftc_family_table_alloc( FTC_FamilyTable   table,
-                          FT_Memory         memory,
-                          FTC_FamilyEntry  *aentry )
+  FTC_Manager_LookupFace( FTC_Manager  manager,
+                          FTC_FaceID   face_id,
+                          FT_Face     *aface )
   {
-    FTC_FamilyEntry  entry;
-    FT_Error         error = 0;
-
-
-    /* re-allocate table size when needed */
-    if ( table->free == FTC_FAMILY_ENTRY_NONE && table->count >= table->size )
-    {
-      FT_UInt  old_size = table->size;
-      FT_UInt  new_size, idx;
-
-
-      if ( old_size == 0 )
-        new_size = 8;
-      else
-      {
-        new_size = old_size * 2;
-
-        /* check for (unlikely) overflow */
-        if ( new_size < old_size )
-          new_size = 65534;
-      }
-
-      if ( FT_RENEW_ARRAY( table->entries, old_size, new_size ) )
-        return error;
-
-      table->size = new_size;
+    FT_Error      error;
+    FTC_FaceNode  node;
 
-      entry       = table->entries + old_size;
-      table->free = old_size;
 
-      for ( idx = old_size; idx + 1 < new_size; idx++, entry++ )
-      {
-        entry->link  = idx + 1;
-        entry->index = idx;
-      }
+    if ( aface == NULL )
+      return FTC_Err_Bad_Argument;
 
-      entry->link  = FTC_FAMILY_ENTRY_NONE;
-      entry->index = idx;
-    }
+    *aface = NULL;
 
-    if ( table->free != FTC_FAMILY_ENTRY_NONE )
-    {
-      entry       = table->entries + table->free;
-      table->free = entry->link;
-    }
-    else if ( table->count < table->size )
-    {
-      entry = table->entries + table->count++;
-    }
-    else
-    {
-      FT_ERROR(( "ftc_family_table_alloc: internal bug!" ));
-      return FTC_Err_Invalid_Argument;
-    }
+    if ( !manager )
+      return FTC_Err_Invalid_Cache_Handle;
 
-    entry->link = FTC_FAMILY_ENTRY_NONE;
-    table->count++;
+    error = FTC_MruList_Lookup( &manager->faces,
+                                face_id,
+                                (FTC_MruNode*) &node );
+    if ( !error )
+      *aface = node->face;
 
-    *aentry = entry;
     return error;
   }
 
 
-  FT_EXPORT_DEF( void )
-  ftc_family_table_free( FTC_FamilyTable  table,
-                         FT_UInt          idx )
-  {
-    /* simply add it to the linked list of free entries */
-    if ( idx < table->count )
-    {
-      FTC_FamilyEntry  entry = table->entries + idx;
-
-
-      if ( entry->link != FTC_FAMILY_ENTRY_NONE )
-        FT_ERROR(( "ftc_family_table_free: internal bug!\n" ));
-      else
-      {
-        entry->link = table->free;
-        table->free = entry->index;
-        table->count--;
-      }
-    }
-  }
 
 
   /*************************************************************************/
@@ -475,41 +323,28 @@
     if ( max_bytes == 0 )
       max_bytes = FTC_MAX_BYTES_DEFAULT;
 
-    error = FT_LruList_New( &ftc_face_list_class,
-                            max_faces,
-                            manager,
-                            memory,
-                            &manager->faces_list );
-    if ( error )
-      goto Exit;
-
-    error = FT_LruList_New( &ftc_size_list_class,
-                            max_sizes,
-                            manager,
-                            memory,
-                            &manager->sizes_list );
-    if ( error )
-      goto Exit;
-
     manager->library      = library;
+    manager->memory       = memory;
     manager->max_weight   = max_bytes;
-    manager->cur_weight   = 0;
 
     manager->request_face = requester;
     manager->request_data = req_data;
 
-    ftc_family_table_init( &manager->families );
+    FTC_MruList_Init( &manager->faces,
+                      &ftc_face_list_class,
+                      max_faces,
+                      manager,
+                      memory );
+
+    FTC_MruList_Init( &manager->sizes,
+                      &ftc_size_list_class,
+                      max_sizes,
+                      manager,
+                      memory );
 
     *amanager = manager;
 
   Exit:
-    if ( error && manager )
-    {
-      FT_LruList_Destroy( manager->faces_list );
-      FT_LruList_Destroy( manager->sizes_list );
-      FT_FREE( manager );
-    }
-
     return error;
   }
 
@@ -526,31 +361,28 @@
     if ( !manager || !manager->library )
       return;
 
-    memory = manager->library->memory;
+    memory = manager->memory;
 
     /* now discard all caches */
-    for (idx = 0; idx < FTC_MAX_CACHES; idx++ )
+    for (idx = manager->num_caches; idx-- > 0; )
     {
       FTC_Cache  cache = manager->caches[idx];
 
-
       if ( cache )
       {
-        cache->clazz->cache_done( cache );
+        cache->clazz.cache_done( cache );
         FT_FREE( cache );
-        manager->caches[idx] = 0;
+        manager->caches[idx] = NULL;
       }
     }
-
-    /* discard families table */
-    ftc_family_table_done( &manager->families, memory );
+    manager->num_caches = 0;
 
     /* discard faces and sizes */
-    FT_LruList_Destroy( manager->faces_list );
-    manager->faces_list = 0;
+    FTC_MruList_Done( &manager->sizes );
+    FTC_MruList_Done( &manager->faces );
 
-    FT_LruList_Destroy( manager->sizes_list );
-    manager->sizes_list = 0;
+    manager->library = NULL;
+    manager->memory  = NULL;
 
     FT_FREE( manager );
   }
@@ -563,8 +395,8 @@
   {
     if ( manager )
     {
-      FT_LruList_Reset( manager->sizes_list );
-      FT_LruList_Reset( manager->faces_list );
+      FTC_MruList_Reset( &manager->sizes );
+      FTC_MruList_Reset( &manager->faces );
     }
     /* XXX: FIXME: flush the caches? */
   }
@@ -576,7 +408,7 @@
   FTC_Manager_Check( FTC_Manager  manager )
   {
     FTC_Node  node, first;
-    
+
 
     first = manager->nodes_list;
 
@@ -584,23 +416,20 @@
     if ( first )
     {
       FT_ULong  weight = 0;
-      
+
 
       node = first;
 
       do
       {
-        FTC_FamilyEntry  entry = manager->families.entries + node->fam_index;
-        FTC_Cache     cache;
+        FTC_Cache     cache = manager->caches + node->cache_index;
 
-        if ( (FT_UInt)node->fam_index >= manager->families.count ||
-             entry->link              != FTC_FAMILY_ENTRY_NONE  )
-          FT_ERROR(( "FTC_Manager_Check: invalid node (family index = %ld\n",
-                     node->fam_index ));
+        if ( (FT_UInt)node->cache_index >= manager->num_caches )
+          FT_ERROR(( "FTC_Manager_Check: invalid node (cache index = %ld\n",
+                     node->cache_index ));
         else
         {
-          cache   = entry->cache;
-          weight += cache->clazz->node_weight( node, cache );
+          weight += cache->clazz.node_weight( node, cache );
         }
 
         node = node->mru_next;
@@ -685,8 +514,8 @@
   /* documentation is in ftcmanag.h */
 
   FT_EXPORT_DEF( FT_Error )
-  FTC_Manager_Register_Cache( FTC_Manager      manager,
-                              FTC_Cache_Class  clazz,
+  FTC_Manager_RegisterCache( FTC_Manager      manager,
+                              FTC_CacheClass   clazz,
                               FTC_Cache       *acache )
   {
     FT_Error   error = FTC_Err_Invalid_Argument;
@@ -695,50 +524,36 @@
 
     if ( manager && clazz && acache )
     {
-      FT_Memory  memory = manager->library->memory;
-      FT_UInt    idx  = 0;
+      FT_Memory  memory = manager->memory;
 
-
-      /* check for an empty cache slot in the manager's table */
-      for ( idx = 0; idx < FTC_MAX_CACHES; idx++ )
-      {
-        if ( manager->caches[idx] == 0 )
-          break;
-      }
-
-      /* return an error if there are too many registered caches */
-      if ( idx >= FTC_MAX_CACHES )
+      if ( manager->num_caches >= FTC_MAX_CACHES )
       {
         error = FTC_Err_Too_Many_Caches;
-        FT_ERROR(( "FTC_Manager_Register_Cache:" ));
-        FT_ERROR(( " too many registered caches\n" ));
+        FT_ERROR(( "%s: too many registered caches\n",
+                   "FTC_Manager_Register_Cache" ));
         goto Exit;
       }
 
       if ( !FT_ALLOC( cache, clazz->cache_size ) )
       {
-        cache->manager = manager;
-        cache->memory  = memory;
-        cache->clazz   = clazz;
+        cache->manager   = manager;
+        cache->memory    = memory;
+        cache->clazz     = clazz[0];
+        cache->org_class = clazz;
 
         /* THIS IS VERY IMPORTANT!  IT WILL WRETCH THE MANAGER */
         /* IF IT IS NOT SET CORRECTLY                          */
-        cache->cache_index = idx;
+        cache->index = manager->num_caches;
 
-        if ( clazz->cache_init )
+        error = clazz->cache_init( cache );
+        if ( error )
         {
-          error = clazz->cache_init( cache );
-          if ( error )
-          {
-            if ( clazz->cache_done )
-              clazz->cache_done( cache );
-
-            FT_FREE( cache );
-            goto Exit;
-          }
+          clazz->cache_done( cache );
+          FT_FREE( cache );
+          goto Exit;
         }
 
-        manager->caches[idx] = cache;
+        manager->caches[ manager->num_caches++ ] = cache;
       }
     }
 
@@ -748,17 +563,65 @@
   }
 
 
+  FT_EXPORT_DEF( FT_UInt )
+  FTC_Manager_FlushN( FTC_Manager  manager,
+                       FT_UInt      count )
+  {
+    FTC_Node  first = manager->nodes_list;
+    FTC_Node  node;
+    FT_UInt   result;
+
+    /* try to remove "count" nodes from the list */
+    if ( first == NULL )  /* empty list! */
+      return 0;
+
+    /* go to last node - it's a circular list */
+    node = first->mru_prev;
+    for ( result = 0; result < count; )
+    {
+      FTC_Node  prev = node->mru_prev;
+
+
+     /* don't touch locked nodes */
+      if ( node->ref_count <= 0 )
+      {
+        ftc_node_destroy( node, manager );
+        result++;
+      }
+
+      if ( prev == manager->nodes_list )
+        break;
+
+      node = prev;
+    }
+    return  result;
+  }
+
+
+  FT_EXPORT_DEF( void )
+  FTC_Manager_RemoveFaceID( FTC_Manager  manager,
+                            FTC_FaceID   face_id )
+  {
+    FT_UInt  nn;
+
+   /* this will remove all FTC_SizeNode that correspond to
+    * the face_id as well
+    */
+    FTC_MruList_RemoveSelection( &manager->faces, NULL, face_id );
+
+    for ( nn = 0; nn < manager->num_caches; nn++ )
+      FTC_Cache_RemoveFaceID( manager->caches[nn], face_id );
+  }
+
+
   /* documentation is in ftcmanag.h */
 
   FT_EXPORT_DEF( void )
   FTC_Node_Unref( FTC_Node     node,
                   FTC_Manager  manager )
   {
-    if ( node && (FT_UInt)node->fam_index < manager->families.count &&
-         manager->families.entries[node->fam_index].cache )
-    {
+    if ( node && (FT_UInt)node->cache_index < manager->num_caches )
       node->ref_count--;
-    }
   }
 
 
diff --git a/src/cache/ftcmru.c b/src/cache/ftcmru.c
new file mode 100644
index 0000000..bfc7bc5
--- /dev/null
+++ b/src/cache/ftcmru.c
@@ -0,0 +1,204 @@
+#include <ft2build.h>
+#include FT_CACHE_H
+#include FT_CACHE_INTERNAL_MRU_H
+#include FT_INTERNAL_OBJECTS_H
+#include FT_INTERNAL_DEBUG_H
+
+#include "ftcerror.h"
+
+  FT_EXPORT_DEF( void )
+  FTC_MruList_Init( FTC_MruList       list,
+                    FTC_MruListClass  clazz,
+                    FT_UInt           max_nodes,
+                    FT_Pointer        data,
+                    FT_Memory         memory )
+  {
+    list->num_nodes = 0;
+    list->max_nodes = max_nodes;
+    list->nodes     = NULL;
+    list->clazz     = *clazz;
+    list->data      = data;
+    list->memory    = memory;
+  }
+
+
+  static void
+  ftc_mrulist_free_nodes( FTC_MruList  list,
+                          FTC_MruNode *plist )
+  {
+    FT_Memory  memory = list->memory;
+
+    while ( *plist )
+    {
+      FTC_MruNode  node = *plist;
+
+      *plist = node->next;
+
+      if ( list->clazz.node_done )
+        list->clazz.node_done( node, list->data );
+
+      FT_FREE( node );
+    }
+  }
+
+
+  FT_EXPORT( void )
+  FTC_MruList_Reset( FTC_MruList  list )
+  {
+    ftc_mrulist_free_nodes( list, &list->nodes );
+    list->num_nodes = 0;
+  }
+
+
+  FT_EXPORT( void )
+  FTC_MruList_Done( FTC_MruList  list )
+  {
+    FTC_MruList_Reset( list );
+  }
+
+
+  FT_EXPORT( FT_Error )
+  FTC_MruList_Lookup( FTC_MruList   list,
+                      FT_Pointer    key,
+                      FTC_MruNode  *anode )
+  {
+    FT_Memory                memory = list->memory;
+    FTC_MruNode_CompareFunc  compare = list->clazz.node_compare;
+    FTC_MruNode              *plast, *pnode, *pfirst;
+    FTC_MruNode              node;
+    FT_Error                 error = 0;
+
+    pfirst = &list->nodes;
+    plast  = pnode = pfirst;
+
+    for (;;)
+    {
+      node = *pnode;
+      if ( node == NULL )
+        goto NewNode;
+      if ( compare( node, key ) )
+        break;
+      plast = pnode;
+      pnode = &node->next;
+    }
+
+    if ( node != *pfirst )
+    {
+      *pnode     = node->next;
+      node->next = *pfirst;
+      *pfirst    = node;
+    }
+    goto Exit;
+
+  NewNode:
+    if ( list->max_nodes > 0 && list->num_nodes >= list->max_nodes )
+    {
+      node = *plast;
+
+      if ( node )
+      {
+        *plast = NULL;
+        list->num_nodes--;
+
+        if ( list->clazz.node_reset )
+        {
+          error = list->clazz.node_reset( node, key, list->data );
+          if ( !error ) goto AddNode;
+        }
+
+        list->clazz.node_done( node, list->data );
+      }
+    }
+    else if ( FT_ALLOC( node, list->clazz.node_size ) )
+      goto Exit;
+
+    error = list->clazz.node_init( node, key, list->data );
+    if ( error )
+    {
+      if ( list->clazz.node_done )
+        list->clazz.node_done( node, list->data );
+
+      FT_FREE( node );
+      goto Exit;
+    }
+
+  AddNode:
+    node->next  = list->nodes;
+    list->nodes = node;
+    list->num_nodes++;
+
+  Exit:
+    *anode = node;
+    return error;
+  }
+
+
+  FT_EXPORT_DEF( void )
+  FTC_MruList_Remove( FTC_MruList   list,
+                      FTC_MruNode   node )
+  {
+    FTC_MruNode  *pnode = &list->nodes;
+
+    for ( ;; )
+    {
+      if ( *pnode == NULL )  /* should not happen !! */
+      {
+        FT_ERROR(( "%s: trying to remove unknown node !!\n",
+                   "FTC_MruList_Remove" ));
+        return;
+      }
+
+      if ( *pnode == node )
+        break;
+
+      pnode = &node->next;
+    }
+
+    *pnode     = node->next;
+    node->next = NULL;
+    list->num_nodes--;
+
+    {
+      FT_Memory  memory = list->memory;
+
+      if ( list->clazz.node_done )
+        list->clazz.node_done( node, list->data );
+
+      FT_FREE( node );
+    }
+  }
+
+
+  FT_EXPORT_DEF( void )
+  FTC_MruList_RemoveSelection( FTC_MruList              list,
+                               FTC_MruNode_CompareFunc  select,
+                               FT_Pointer               key )
+  {
+    FTC_MruNode  *pnode = &list->nodes;
+    FTC_MruNode   node, free = NULL;;
+
+    if ( select )
+    {
+      for (;;)
+      {
+        FTC_MruNode  node = *pnode;
+
+        if ( node == NULL )
+          break;
+
+        if ( select( node, key ) )
+        {
+          *pnode     = node->next;
+          node->next = free;
+          free       = node;
+        }
+        else
+          pnode = &node->next;
+      }
+    }
+
+    ftc_mrulist_free_nodes( list, &free );
+  }
+
+/* END */
+
diff --git a/src/cache/ftcsbits.c b/src/cache/ftcsbits.c
index 2faf80f..d708d33 100644
--- a/src/cache/ftcsbits.c
+++ b/src/cache/ftcsbits.c
@@ -18,8 +18,7 @@
 
 #include <ft2build.h>
 #include FT_CACHE_H
-#include FT_CACHE_SMALL_BITMAPS_H
-#include FT_CACHE_INTERNAL_GLYPH_H
+#include FT_CACHE_INTERNAL_SBITS_H
 #include FT_INTERNAL_OBJECTS_H
 #include FT_INTERNAL_DEBUG_H
 #include FT_ERRORS_H
@@ -27,47 +26,6 @@
 #include "ftcerror.h"
 
 
-#define FTC_SBIT_ITEMS_PER_NODE  16
-
-
-  typedef struct FTC_SBitNodeRec_*  FTC_SBitNode;
-
-  typedef struct  FTC_SBitNodeRec_
-  {
-    FTC_GlyphNodeRec  gnode;
-    FTC_SBitRec       sbits[FTC_SBIT_ITEMS_PER_NODE];
-
-  } FTC_SBitNodeRec;
-
-
-#define FTC_SBIT_NODE( x )  ( (FTC_SBitNode)( x ) )
-
-
-  typedef struct  FTC_SBitQueryRec_
-  {
-    FTC_GlyphQueryRec  gquery;
-    FTC_ImageTypeRec   type;
-
-  } FTC_SBitQueryRec, *FTC_SBitQuery;
-
-
-#define FTC_SBIT_QUERY( x ) ( (FTC_SBitQuery)( x ) )
-
-
-  typedef struct FTC_SBitFamilyRec_*  FTC_SBitFamily;
-
-  /* sbit family structure */
-  typedef struct  FTC_SBitFamilyRec_
-  {
-    FTC_GlyphFamilyRec  gfam;
-    FTC_ImageTypeRec    type;
-
-  } FTC_SBitFamilyRec;
-
-
-#define FTC_SBIT_FAMILY( x )         ( (FTC_SBitFamily)( x ) )
-#define FTC_SBIT_FAMILY_MEMORY( x )  FTC_GLYPH_FAMILY_MEMORY( &( x )->cset )
-
 
   /*************************************************************************/
   /*************************************************************************/
@@ -100,173 +58,188 @@
   }
 
 
-  FT_CALLBACK_DEF( void )
-  ftc_sbit_node_done( FTC_SBitNode  snode,
-                      FTC_Cache     cache )
+  FT_EXPORT_DEF( void )
+  FTC_SNode_Free( FTC_SNode  snode,
+                  FTC_Cache  cache )
   {
     FTC_SBit   sbit   = snode->sbits;
-    FT_UInt    count  = FTC_GLYPH_NODE( snode )->item_count;
+    FT_UInt    count  = snode->count;
     FT_Memory  memory = cache->memory;
 
 
     for ( ; count > 0; sbit++, count-- )
       FT_FREE( sbit->buffer );
 
-    ftc_glyph_node_done( FTC_GLYPH_NODE( snode ), cache );
+    FTC_GNode_Done( FTC_GNODE( snode ), cache );
+
+    FT_FREE( snode );
   }
 
 
   static FT_Error
-  ftc_sbit_node_load( FTC_SBitNode    snode,
-                      FTC_Manager     manager,
-                      FTC_SBitFamily  sfam,
-                      FT_UInt         gindex,
-                      FT_ULong       *asize )
+  ftc_snode_load( FTC_SNode       snode,
+                  FTC_Manager     manager,
+                  FT_UInt         gindex,
+                  FT_ULong       *asize )
   {
-    FT_Error       error;
-    FTC_GlyphNode  gnode = FTC_GLYPH_NODE( snode );
-    FT_Memory      memory;
-    FT_Face        face;
-    FT_Size        size;
-    FTC_SBit       sbit;
+    FT_Error           error;
+    FTC_GNode          gnode  = FTC_GNODE( snode );
+    FTC_Family         family = gnode->family;
+    FT_Memory          memory = manager->memory;
+    FT_Face            face;
+    FTC_SBit           sbit;
+    FTC_SFamilyClass   clazz;
 
 
-    if ( gindex <  (FT_UInt)gnode->item_start                     ||
-         gindex >= (FT_UInt)gnode->item_start + gnode->item_count )
+    if ( (FT_UInt)gindex >= gnode->gindex + snode->count )
     {
-      FT_ERROR(( "ftc_sbit_node_load: invalid glyph index" ));
+      FT_ERROR(( "ftc_snode_load: invalid glyph index" ));
       return FTC_Err_Invalid_Argument;
     }
 
-    memory = manager->library->memory;
+    sbit   = snode->sbits + ( gindex - gnode->gindex );
+    clazz  = (FTC_SFamilyClass) family->clazz;
 
-    sbit = snode->sbits + ( gindex - gnode->item_start );
+    sbit->buffer = 0;
+
+    error = clazz->family_load_glyph( family, gindex, manager, &face );
+    if ( error )
+      goto BadGlyph;
 
-    error = FTC_Manager_Lookup_Size( manager, &sfam->type.font,
-                                     &face, &size );
-    if ( !error )
     {
-      /* by default, indicates a `missing' glyph */
-      sbit->buffer = 0;
+      FT_Int        temp;
+      FT_GlyphSlot  slot   = face->glyph;
+      FT_Bitmap*    bitmap = &slot->bitmap;
+      FT_Int        xadvance, yadvance;
 
-      error = FT_Load_Glyph( face, gindex, sfam->type.flags | FT_LOAD_RENDER );
-      if ( !error )
+      if ( slot->format != FT_GLYPH_FORMAT_BITMAP )
       {
-        FT_Int        temp;
-        FT_GlyphSlot  slot   = face->glyph;
-        FT_Bitmap*    bitmap = &slot->bitmap;
-        FT_Int        xadvance, yadvance;
-
+        FT_ERROR(( "%s: glyph loaded didn't returned a bitmap !!\n",
+                   "ftc_snode_load" ));
+        goto BadGlyph;
+      }
 
-        /* check that our values fit into 8-bit containers!       */
-        /* If this is not the case, our bitmap is too large       */
-        /* and we will leave it as `missing' with sbit.buffer = 0 */
+      /* check that our values fit into 8-bit containers!       */
+      /* If this is not the case, our bitmap is too large       */
+      /* and we will leave it as `missing' with sbit.buffer = 0 */
 
 #define CHECK_CHAR( d )  ( temp = (FT_Char)d, temp == d )
 #define CHECK_BYTE( d )  ( temp = (FT_Byte)d, temp == d )
 
-        /* XXX: FIXME: add support for vertical layouts maybe */
-
-        /* horizontal advance in pixels */
-        xadvance = ( slot->metrics.horiAdvance + 32 ) >> 6;
-        yadvance = ( slot->metrics.vertAdvance + 32 ) >> 6;
-
-        if ( CHECK_BYTE( bitmap->rows  )     &&
-             CHECK_BYTE( bitmap->width )     &&
-             CHECK_CHAR( bitmap->pitch )     &&
-             CHECK_CHAR( slot->bitmap_left ) &&
-             CHECK_CHAR( slot->bitmap_top  ) &&
-             CHECK_CHAR( xadvance )          &&
-             CHECK_CHAR( yadvance )          )
-        {
-          sbit->width     = (FT_Byte)bitmap->width;
-          sbit->height    = (FT_Byte)bitmap->rows;
-          sbit->pitch     = (FT_Char)bitmap->pitch;
-          sbit->left      = (FT_Char)slot->bitmap_left;
-          sbit->top       = (FT_Char)slot->bitmap_top;
-          sbit->xadvance  = (FT_Char)xadvance;
-          sbit->yadvance  = (FT_Char)yadvance;
-          sbit->format    = (FT_Byte)bitmap->pixel_mode;
-          sbit->max_grays = (FT_Byte)(bitmap->num_grays - 1);
-
-#if 0 /* this doesn't work well with embedded bitmaps */
-
-          /* grab the bitmap when possible - this is a hack! */
-          if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
-          {
-            slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
-            sbit->buffer           = bitmap->buffer;
-          }
-          else
-#endif
-          {
-            /* copy the bitmap into a new buffer -- ignore error */
-            error = ftc_sbit_copy_bitmap( sbit, bitmap, memory );
-          }
-
-          /* now, compute size */
-          if ( asize )
-            *asize = ABS( sbit->pitch ) * sbit->height;
-
-        }  /* glyph dimensions ok */
-
-      } /* glyph loading successful */
-
-      /* ignore the errors that might have occurred --   */
-      /* we mark unloaded glyphs with `sbit.buffer == 0' */
-      /* and 'width == 255', 'height == 0'               */
-      /*                                                 */
-      if ( error && error != FTC_Err_Out_Of_Memory )
-      {
-        sbit->width = 255;
-        error       = 0;
-        /* sbit->buffer == NULL too! */
-      }
+      /* horizontal advance in pixels */
+      xadvance = ( slot->metrics.horiAdvance + 32 ) >> 6;
+      yadvance = ( slot->metrics.vertAdvance + 32 ) >> 6;
+
+      if ( !CHECK_BYTE( bitmap->rows  )     ||
+           !CHECK_BYTE( bitmap->width )     ||
+           !CHECK_CHAR( bitmap->pitch )     ||
+           !CHECK_CHAR( slot->bitmap_left ) ||
+           !CHECK_CHAR( slot->bitmap_top  ) ||
+           !CHECK_CHAR( xadvance )          ||
+           !CHECK_CHAR( yadvance )          )
+        goto BadGlyph;
+
+      sbit->width     = (FT_Byte)bitmap->width;
+      sbit->height    = (FT_Byte)bitmap->rows;
+      sbit->pitch     = (FT_Char)bitmap->pitch;
+      sbit->left      = (FT_Char)slot->bitmap_left;
+      sbit->top       = (FT_Char)slot->bitmap_top;
+      sbit->xadvance  = (FT_Char)xadvance;
+      sbit->yadvance  = (FT_Char)yadvance;
+      sbit->format    = (FT_Byte)bitmap->pixel_mode;
+      sbit->max_grays = (FT_Byte)(bitmap->num_grays - 1);
+
+      /* copy the bitmap into a new buffer -- ignore error */
+      error = ftc_sbit_copy_bitmap( sbit, bitmap, memory );
+
+      /* now, compute size */
+      if ( asize )
+        *asize = ABS( sbit->pitch ) * sbit->height;
+
+    } /* glyph loading successful */
+
+    /* ignore the errors that might have occurred --   */
+    /* we mark unloaded glyphs with `sbit.buffer == 0' */
+    /* and 'width == 255', 'height == 0'               */
+    /*                                                 */
+    if ( error && error != FTC_Err_Out_Of_Memory )
+    {
+    BadGlyph:
+      sbit->width  = 255;
+      sbit->height = 0;
+      sbit->buffer = NULL;
+      error        = 0;
     }
 
     return error;
   }
 
 
-  FT_CALLBACK_DEF( FT_Error )
-  ftc_sbit_node_init( FTC_SBitNode    snode,
-                      FTC_GlyphQuery  gquery,
-                      FTC_Cache       cache )
+  FT_EXPORT_DEF( FT_Error )
+  FTC_SNode_New( FTC_SNode  *psnode,
+                 FTC_GQuery  gquery,
+                 FTC_Cache   cache )
   {
-    FT_Error  error;
+    FT_Memory   memory = cache->memory;
+    FT_Error    error;
+    FTC_SNode   snode  = NULL;
+    FT_UInt     gindex = gquery->gindex;
+    FTC_Family  family = gquery->family;
 
+    FTC_SFamilyClass  clazz = FTC_CACHE__SFAMILY_CLASS( cache );
+    FT_UInt           total;
 
-    ftc_glyph_node_init( FTC_GLYPH_NODE( snode ),
-                         gquery->gindex,
-                         FTC_GLYPH_FAMILY( gquery->query.family ) );
+    total = clazz->family_get_count( family, cache->manager );
+    if ( total == 0 || gindex >= total )
+    {
+      error = FT_Err_Invalid_Argument;
+      goto Exit;
+    }
 
-    error = ftc_sbit_node_load( snode,
-                                cache->manager,
-                                FTC_SBIT_FAMILY( FTC_QUERY( gquery )->family ),
-                                gquery->gindex,
-                                NULL );
-    if ( error )
-      ftc_glyph_node_done( FTC_GLYPH_NODE( snode ), cache );
+    if ( !FT_NEW( snode ) )
+    {
+      FT_UInt   count, start;
+
+      start = gindex - (gindex % FTC_SBIT_ITEMS_PER_NODE);
+      count = total - start;
+      if ( count > FTC_SBIT_ITEMS_PER_NODE )
+        count = FTC_SBIT_ITEMS_PER_NODE;
 
+      FTC_GNode_Init( FTC_GNODE( snode ), start, family );
+
+      snode->count = count;
+
+      error = ftc_snode_load( snode,
+                              cache->manager,
+                              gindex,
+                              NULL );
+      if ( error )
+      {
+        FTC_SNode_Free( snode, cache );
+        snode = NULL;
+      }
+    }
+
+  Exit:
+    *psnode = snode;
     return error;
   }
 
 
-  FT_CALLBACK_DEF( FT_ULong )
-  ftc_sbit_node_weight( FTC_SBitNode  snode )
+  FT_EXPORT_DEF( FT_ULong )
+  FTC_SNode_Weight( FTC_SNode  snode )
   {
-    FTC_GlyphNode  gnode = FTC_GLYPH_NODE( snode );
-    FT_UInt        count = gnode->item_count;
-    FTC_SBit       sbit  = snode->sbits;
-    FT_Int         pitch;
-    FT_ULong       size;
+    FT_UInt    count = snode->count;
+    FTC_SBit   sbit  = snode->sbits;
+    FT_Int     pitch;
+    FT_ULong   size;
 
 
     /* the node itself */
     size = sizeof ( *snode );
 
     /* the sbit records */
-    size += FTC_GLYPH_NODE( snode )->item_count * sizeof ( FTC_SBitRec );
+    size += count * sizeof( FTC_SBitRec );
 
     for ( ; count > 0; count--, sbit++ )
     {
@@ -285,22 +258,20 @@
   }
 
 
-  FT_CALLBACK_DEF( FT_Bool )
-  ftc_sbit_node_compare( FTC_SBitNode   snode,
-                         FTC_SBitQuery  squery,
-                         FTC_Cache      cache )
+  FT_EXPORT_DEF( FT_Bool )
+  FTC_SNode_Compare( FTC_SNode   snode,
+                     FTC_GQuery  gquery,
+                     FTC_Cache   cache )
   {
-    FTC_GlyphQuery  gquery = FTC_GLYPH_QUERY( squery );
-    FTC_GlyphNode   gnode  = FTC_GLYPH_NODE( snode );
-    FT_Bool         result;
-
+    FTC_GNode   gnode  = FTC_GNODE( snode );
+    FT_UInt     gindex = gquery->gindex;
+    FT_Bool     result;
 
-    result = ftc_glyph_node_compare( gnode, gquery );
+    result = FT_BOOL( (FT_UInt)(gindex - gnode->gindex) < snode->count );
     if ( result )
     {
       /* check if we need to load the glyph bitmap now */
-      FT_UInt   gindex = gquery->gindex;
-      FTC_SBit  sbit   = snode->sbits + ( gindex - gnode->item_start );
+      FTC_SBit  sbit = snode->sbits + ( gindex - gnode->gindex );
 
 
       if ( sbit->buffer == NULL && sbit->width != 255 )
@@ -308,247 +279,15 @@
         FT_ULong  size;
 
 
-        if ( !ftc_sbit_node_load(
-                snode, cache->manager,
-                FTC_SBIT_FAMILY( FTC_QUERY( squery )->family ),
-                gindex, &size ) )
+        if ( !ftc_snode_load( snode, cache->manager,
+                              gindex, &size ) )
+        {
           cache->manager->cur_weight += size;
+        }
       }
     }
 
     return result;
   }
 
-
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                     SBITS FAMILIES                            *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-
-
-  FT_CALLBACK_DEF( FT_Error )
-  ftc_sbit_family_init( FTC_SBitFamily  sfam,
-                        FTC_SBitQuery   squery,
-                        FTC_Cache       cache )
-  {
-    FTC_Manager  manager = cache->manager;
-    FT_Error     error;
-    FT_Face      face;
-
-
-    sfam->type = squery->type;
-
-    /* we need to compute "cquery.item_total" now */
-    error = FTC_Manager_Lookup_Face( manager,
-                                     squery->type.font.face_id,
-                                     &face );
-    if ( !error )
-    {
-      error = ftc_glyph_family_init( FTC_GLYPH_FAMILY( sfam ),
-                                     FTC_IMAGE_TYPE_HASH( &sfam->type ),
-                                     FTC_SBIT_ITEMS_PER_NODE,
-                                     face->num_glyphs,
-                                     FTC_GLYPH_QUERY( squery ),
-                                     cache );
-    }
-
-    return error;
-  }
-
-
-  FT_CALLBACK_DEF( FT_Bool )
-  ftc_sbit_family_compare( FTC_SBitFamily  sfam,
-                           FTC_SBitQuery   squery )
-  {
-    FT_Bool  result;
-
-
-    /* we need to set the "cquery.cset" field or our query for */
-    /* faster glyph comparisons in ftc_sbit_node_compare       */
-    /*                                                         */
-    result = FT_BOOL( FTC_IMAGE_TYPE_COMPARE( &sfam->type, &squery->type ) );
-    if ( result )
-      FTC_GLYPH_FAMILY_FOUND( sfam, squery );
-
-    return result;
-  }
-
-
-  /*************************************************************************/
-  /*************************************************************************/
-  /*****                                                               *****/
-  /*****                     SBITS CACHE                               *****/
-  /*****                                                               *****/
-  /*************************************************************************/
-  /*************************************************************************/
-
-
-  FT_CALLBACK_TABLE_DEF
-  const FTC_Cache_ClassRec  ftc_sbit_cache_class =
-  {
-    sizeof ( FTC_CacheRec ),
-    (FTC_Cache_InitFunc) ftc_cache_init,
-    (FTC_Cache_ClearFunc)ftc_cache_clear,
-    (FTC_Cache_DoneFunc) ftc_cache_done,
-
-    sizeof ( FTC_SBitFamilyRec ),
-    (FTC_Family_InitFunc)   ftc_sbit_family_init,
-    (FTC_Family_CompareFunc)ftc_sbit_family_compare,
-    (FTC_Family_DoneFunc)   ftc_glyph_family_done,
-
-    sizeof ( FTC_SBitNodeRec ),
-    (FTC_Node_InitFunc)   ftc_sbit_node_init,
-    (FTC_Node_WeightFunc) ftc_sbit_node_weight,
-    (FTC_Node_CompareFunc)ftc_sbit_node_compare,
-    (FTC_Node_DoneFunc)   ftc_sbit_node_done
-  };
-
-
-  /* documentation is in ftcsbits.h */
-
-  FT_EXPORT_DEF( FT_Error )
-  FTC_SBitCache_New( FTC_Manager     manager,
-                     FTC_SBitCache  *acache )
-  {
-    return FTC_Manager_Register_Cache( manager,
-                                       &ftc_sbit_cache_class,
-                                       (FTC_Cache*)acache );
-  }
-
-
-  /* documentation is in ftcsbits.h */
-
-#ifdef FTC_CACHE_USE_INLINE
-
-#define GEN_CACHE_FAMILY_COMPARE( f, q, c ) \
-          ftc_sbit_family_compare( (FTC_SBitFamily)(f), (FTC_SBitQuery)(q) )
-
-#define GEN_CACHE_NODE_COMPARE( n, q, c ) \
-          ftc_sbit_node_compare( (FTC_SBitNode)(n), (FTC_SBitQuery)(q), c )
-
-#define GEN_CACHE_LOOKUP  ftc_sbit_cache_lookup
-#include "ftccache.i"
-
-#else  /* !FTC_CACHE_USE_INLINE */
-
-#define ftc_sbit_cache_lookup  ftc_cache_lookup
-
-#endif /* !FTC_CACHE_USE_INLINE */
-
-  FT_EXPORT_DEF( FT_Error )
-  FTC_SBitCache_Lookup( FTC_SBitCache   cache,
-                        FTC_ImageType   type,
-                        FT_UInt         gindex,
-                        FTC_SBit       *ansbit,
-                        FTC_Node       *anode )
-  {
-    FT_Error          error;
-    FTC_SBitQueryRec  squery;
-    FTC_SBitNode      node;
-
-
-    /* other argument checks delayed to ftc_cache_lookup */
-    if ( !ansbit )
-      return FTC_Err_Invalid_Argument;
-
-    *ansbit = NULL;
-
-    if ( anode )
-      *anode = NULL;
-
-    squery.gquery.gindex = gindex;
-    squery.type          = *type;
-
-    error = ftc_sbit_cache_lookup( FTC_CACHE( cache ),
-                                   FTC_QUERY( &squery ),
-                                   (FTC_Node*)&node );
-    if ( !error )
-    {
-      *ansbit = node->sbits + ( gindex - FTC_GLYPH_NODE( node )->item_start );
-
-      if ( anode )
-      {
-        *anode = FTC_NODE( node );
-        FTC_NODE( node )->ref_count++;
-      }
-    }
-    return error;
-  }
-
-
-  /* backwards-compatibility functions */
-
-  FT_EXPORT_DEF( FT_Error )
-  FTC_SBit_Cache_New( FTC_Manager      manager,
-                      FTC_SBit_Cache  *acache )
-  {
-    return FTC_SBitCache_New( manager, (FTC_SBitCache*)acache );
-  }
-
-
-  FT_EXPORT_DEF( FT_Error )
-  FTC_SBit_Cache_Lookup( FTC_SBit_Cache   cache,
-                         FTC_Image_Desc*  desc,
-                         FT_UInt          gindex,
-                         FTC_SBit        *ansbit )
-  {
-    FTC_ImageTypeRec  type0;
-
-
-    if ( !desc )
-      return FTC_Err_Invalid_Argument;
-
-    type0.font  = desc->font;
-    type0.flags = 0;
-
-    /* convert image type flags to load flags */
-    {
-      FT_UInt  load_flags = FT_LOAD_DEFAULT;
-      FT_UInt  type       = desc->image_type;
-
-
-      /* determine load flags, depending on the font description's */
-      /* image type                                                */
-
-      if ( ftc_image_format( type ) == ftc_image_format_bitmap )
-      {
-        if ( type & ftc_image_flag_monochrome )
-          load_flags |= FT_LOAD_MONOCHROME;
-
-        /* disable embedded bitmaps loading if necessary */
-        if ( type & ftc_image_flag_no_sbits )
-          load_flags |= FT_LOAD_NO_BITMAP;
-      }
-      else
-      {
-        /* we want an outline, don't load embedded bitmaps */
-        load_flags |= FT_LOAD_NO_BITMAP;
-
-        if ( type & ftc_image_flag_unscaled )
-          load_flags |= FT_LOAD_NO_SCALE;
-      }
-
-      /* always render glyphs to bitmaps */
-      load_flags |= FT_LOAD_RENDER;
-
-      if ( type & ftc_image_flag_unhinted )
-        load_flags |= FT_LOAD_NO_HINTING;
-
-      if ( type & ftc_image_flag_autohinted )
-        load_flags |= FT_LOAD_FORCE_AUTOHINT;
-
-      type0.flags = load_flags;
-    }
-
-    return FTC_SBitCache_Lookup( (FTC_SBitCache)cache,
-                                  &type0,
-                                  gindex,
-                                  ansbit,
-                                  NULL );
-  }
-
-
 /* END */
diff --git a/src/cache/ftlru.c b/src/cache/ftlru.c
deleted file mode 100644
index b25d741..0000000
--- a/src/cache/ftlru.c
+++ /dev/null
@@ -1,390 +0,0 @@
-/***************************************************************************/
-/*                                                                         */
-/*  ftlru.c                                                                */
-/*                                                                         */
-/*    Simple LRU list-cache (body).                                        */
-/*                                                                         */
-/*  Copyright 2000-2001, 2002, 2003 by                                     */
-/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
-/*                                                                         */
-/*  This file is part of the FreeType project, and may only be used,       */
-/*  modified, and distributed under the terms of the FreeType project      */
-/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
-/*  this file you indicate that you have read the license and              */
-/*  understand and accept it fully.                                        */
-/*                                                                         */
-/***************************************************************************/
-
-
-#include <ft2build.h>
-#include FT_CACHE_H
-#include FT_CACHE_INTERNAL_LRU_H
-#include FT_LIST_H
-#include FT_INTERNAL_OBJECTS_H
-#include FT_INTERNAL_DEBUG_H
-
-#include "ftcerror.h"
-
-
-  FT_EXPORT_DEF( FT_Error )
-  FT_LruList_New( FT_LruList_Class  clazz,
-                  FT_UInt           max_nodes,
-                  FT_Pointer        user_data,
-                  FT_Memory         memory,
-                  FT_LruList       *alist )
-  {
-    FT_Error    error;
-    FT_LruList  list;
-
-
-    if ( !alist || !clazz )
-      return FTC_Err_Invalid_Argument;
-
-    *alist = NULL;
-    if ( !FT_ALLOC( list, clazz->list_size ) )
-    {
-      /* initialize common fields */
-      list->clazz      = clazz;
-      list->memory     = memory;
-      list->max_nodes  = max_nodes;
-      list->data       = user_data;
-
-      if ( clazz->list_init )
-      {
-        error = clazz->list_init( list );
-        if ( error )
-        {
-          if ( clazz->list_done )
-            clazz->list_done( list );
-
-          FT_FREE( list );
-        }
-      }
-
-      *alist = list;
-    }
-
-    return error;
-  }
-
-
-  FT_EXPORT_DEF( void )
-  FT_LruList_Destroy( FT_LruList  list )
-  {
-    FT_Memory         memory;
-    FT_LruList_Class  clazz;
-
-
-    if ( !list )
-      return;
-
-    memory = list->memory;
-    clazz  = list->clazz;
-
-    FT_LruList_Reset( list );
-
-    if ( clazz->list_done )
-      clazz->list_done( list );
-
-    FT_FREE( list );
-  }
-
-
-  FT_EXPORT_DEF( void )
-  FT_LruList_Reset( FT_LruList  list )
-  {
-    FT_LruNode        node;
-    FT_LruList_Class  clazz;
-    FT_Memory         memory;
-
-
-    if ( !list )
-      return;
-
-    node   = list->nodes;
-    clazz  = list->clazz;
-    memory = list->memory;
-
-    while ( node )
-    {
-      FT_LruNode  next = node->next;
-
-
-      if ( clazz->node_done )
-        clazz->node_done( node, list->data );
-
-      FT_FREE( node );
-      node = next;
-    }
-
-    list->nodes     = NULL;
-    list->num_nodes = 0;
-  }
-
-
-  FT_EXPORT_DEF( FT_Error )
-  FT_LruList_Lookup( FT_LruList   list,
-                     FT_LruKey    key,
-                     FT_LruNode  *anode )
-  {
-    FT_Error          error = 0;
-    FT_LruNode        node, *pnode;
-    FT_LruList_Class  clazz;
-    FT_LruNode        result = NULL;
-    FT_Memory         memory;
-
-
-    if ( !list || !key || !anode )
-      return FTC_Err_Invalid_Argument;
-
-    pnode  = &list->nodes;
-    node   = NULL;
-    clazz  = list->clazz;
-    memory = list->memory;
-
-    if ( clazz->node_compare )
-    {
-      for (;;)
-      {
-        node = *pnode;
-        if ( node == NULL )
-          break;
-
-        if ( clazz->node_compare( node, key, list->data ) )
-          break;
-
-        pnode = &(*pnode)->next;
-      }
-    }
-    else
-    {
-      for (;;)
-      {
-        node = *pnode;
-        if ( node == NULL )
-          break;
-
-        if ( node->key == key )
-          break;
-
-        pnode = &(*pnode)->next;
-      }
-    }
-
-    if ( node )
-    {
-      /* move element to top of list */
-      if ( list->nodes != node )
-      {
-        *pnode      = node->next;
-        node->next  = list->nodes;
-        list->nodes = node;
-      }
-      result = node;
-      goto Exit;
-    }
-
-   /* Since we haven't found the relevant element in our LRU list,
-    * we're going to "create" a new one.
-    *
-    * The following code is a bit special, because it tries to handle
-    * out-of-memory conditions (OOM) in an intelligent way.
-    *
-    * More precisely, if not enough memory is available to create a
-    * new node or "flush" an old one, we need to remove the oldest
-    * elements from our list, and try again.  Since several tries may
-    * be necessary, a loop is needed.
-    *
-    * This loop will only exit when:
-    *
-    *   - a new node was successfully created, or an old node flushed
-    *   - an error other than FTC_Err_Out_Of_Memory is detected
-    *   - the list of nodes is empty, and it isn't possible to create
-    *     new nodes
-    *
-    * On each unsuccessful attempt, one node will be removed from the list.
-    *
-    */
-    
-    {
-      FT_Int  drop_last = ( list->max_nodes > 0 && 
-                            list->num_nodes >= list->max_nodes );
-
-      for (;;)
-      {
-        node = NULL;
-
-        /* If "drop_last" is true, we should free the last node in
-         * the list to make room for a new one.  Note that we reuse
-         * its memory block to save allocation calls.
-         */
-        if ( drop_last )
-        {
-         /* find the last node in the list
-          */
-          pnode = &list->nodes;
-          node  = *pnode;
-  
-          if ( node == NULL )
-          {
-            FT_ASSERT( list->num_nodes == 0 );
-            error = FTC_Err_Out_Of_Memory;
-            goto Exit;
-          }
-
-          FT_ASSERT( list->num_nodes > 0 );
-
-          while ( node->next )
-          {
-            pnode = &node->next;
-            node  = *pnode;
-          }
-  
-          /* Remove it from the list, and try to "flush" it.  Doing this will
-           * save a significant number of dynamic allocations compared to
-           * a classic destroy/create cycle.
-           */
-          *pnode = NULL;
-          list->num_nodes--;
-  
-          if ( clazz->node_flush )
-          {
-            error = clazz->node_flush( node, key, list->data );
-            if ( !error )
-              goto Success;
-
-           /* Note that if an error occured during the flush, we need to
-            * finalize it since it is potentially in incomplete state.
-            */
-          }
-
-          /* We finalize, but do not destroy the last node, we
-           * simply reuse its memory block!
-           */
-          if ( clazz->node_done )
-            clazz->node_done( node, list->data );
-            
-          FT_MEM_ZERO( node, clazz->node_size );
-        }
-        else
-        {
-         /* Try to allocate a new node when "drop_last" is not TRUE.
-          * This usually happens on the first pass, when the LRU list
-          * is not already full.
-          */
-          if ( FT_ALLOC( node, clazz->node_size ) )
-            goto Fail;
-        }
-  
-        FT_ASSERT( node != NULL );
-
-        node->key = key;
-        error = clazz->node_init( node, key, list->data );
-        if ( error )
-        {
-          if ( clazz->node_done )
-            clazz->node_done( node, list->data );
-
-          FT_FREE( node );
-          goto Fail;
-        }
-
-      Success:
-        result = node;
-
-        node->next  = list->nodes;
-        list->nodes = node;
-        list->num_nodes++;
-        goto Exit;
-  
-      Fail:
-        if ( error != FTC_Err_Out_Of_Memory )
-          goto Exit;
-        
-        drop_last = 1;
-        continue;
-      }
-    }
-
-  Exit:
-    *anode = result;
-    return error;
-  }
-
-
-  FT_EXPORT_DEF( void )
-  FT_LruList_Remove( FT_LruList  list,
-                     FT_LruNode  node )
-  {
-    FT_LruNode  *pnode;
-
-
-    if ( !list || !node )
-      return;
-
-    pnode = &list->nodes;
-    for (;;)
-    {
-      if ( *pnode == node )
-      {
-        FT_Memory         memory = list->memory;
-        FT_LruList_Class  clazz  = list->clazz;
-
-
-        *pnode     = node->next;
-        node->next = NULL;
-
-        if ( clazz->node_done )
-          clazz->node_done( node, list->data );
-
-        FT_FREE( node );
-        list->num_nodes--;
-        break;
-      }
-
-      pnode = &(*pnode)->next;
-    }
-  }
-
-
-  FT_EXPORT_DEF( void )
-  FT_LruList_Remove_Selection( FT_LruList             list,
-                               FT_LruNode_SelectFunc  select_func,
-                               FT_Pointer             select_data )
-  {
-    FT_LruNode       *pnode, node;
-    FT_LruList_Class  clazz;
-    FT_Memory         memory;
-
-
-    if ( !list || !select_func )
-      return;
-
-    memory = list->memory;
-    clazz  = list->clazz;
-    pnode  = &list->nodes;
-
-    for (;;)
-    {
-      node = *pnode;
-      if ( node == NULL )
-        break;
-
-      if ( select_func( node, select_data, list->data ) )
-      {
-        *pnode     = node->next;
-        node->next = NULL;
-
-        if ( clazz->node_done )
-          clazz->node_done( node, list );
-
-        FT_FREE( node );
-        list->num_nodes--;
-      }
-      else
-        pnode = &(*pnode)->next;
-    }
-  }
-
-
-/* END */
diff --git a/src/cache/rules.mk b/src/cache/rules.mk
index 617ca48..154f126 100644
--- a/src/cache/rules.mk
+++ b/src/cache/rules.mk
@@ -25,8 +25,9 @@ CACHE_COMPILE := $(FT_COMPILE) $I$(subst /,$(COMPILER_SEP),$(CACHE_DIR))
 
 # Cache driver sources (i.e., C files)
 #
-CACHE_DRV_SRC := $(CACHE_DIR)/ftlru.c    \
+CACHE_DRV_SRC := $(CACHE_DIR)/ftcmru.c   \
                  $(CACHE_DIR)/ftcmanag.c \
+                 $(CACHE_DIR)/ftcbasic.c \
                  $(CACHE_DIR)/ftccache.c \
                  $(CACHE_DIR)/ftcglyph.c \
                  $(CACHE_DIR)/ftcsbits.c \
@@ -35,10 +36,11 @@ CACHE_DRV_SRC := $(CACHE_DIR)/ftlru.c    \
 
 # Cache driver headers
 #
-CACHE_DRV_H := $(CACHE_H_DIR)/ftlru.h    \
+CACHE_DRV_H := $(CACHE_H_DIR)/ftcmru.h   \
                $(CACHE_H_DIR)/ftcmanag.h \
                $(CACHE_H_DIR)/ftcglyph.h \
                $(CACHE_H_DIR)/ftcimage.h \
+               $(CACHE_H_DIR)/ftccmap.h  \
                $(CACHE_DIR)/ftcerror.h