If you did want to cache every possible end-game then I'd advise you to look into data storage requirements first. If you have 24 plays left, that suggests 24 gaps on the board, which suggests 24 * 23 * 22 * 21 *.... * 2 * 1 possible moves (at most) which is about
: 51,090,942,171,709,440,000 possibilities. Of course, most of those will be illegal but even if you assumed 1% of them were legal, you'd still have an awfully large number of positions on the board left after you apply the games rules. Multiply that by the storage size of each move and you can come up with quite a hefty lookup in order to find the "perfect" ending for any one particular board position and huge memory requirements. This is where algorithms beat the caching of their results. Also, it would have to pre-calculate, or have experienced, most of those endings to actually make itself useful.
If you *did* insist on going that way, you'd need what you'd need for any similar task - a way of recording the board position uniquely as a string of some data, and a way to store and retrieve huge numbers of those data strings efficiently. Hash trees, etc. might be worth a read up on.
But my advice? Look at what you could potentially be storing on your average PC and just how much that information is going to be worth to you at runtime.