docs: def _get_keycachelike(self, keycache, keys, get_adds_dels, parentity, branch, turn, tick, *, forward):
          """Try to retrieve a frozenset representing extant keys.
  
          If I can't, generate one, store it, and return it.
  
          """
          keycache_key = parentity + (branch,)
          keycache2 = keycache3 = None
          if keycache_key in keycache:
              keycache2 = keycache[keycache_key]
              if turn in keycache2:
                  keycache3 = keycache2[turn]
                  if tick in keycache3:
                      return keycache3[tick]
          if forward:
              # Take valid values from the past of a keycache and copy them forward, into the present.
              # Assumes that time is only moving forward, never backward, never skipping any turns or ticks,
              # and any changes to the world state are happening through allegedb proper, meaning they'll all get cached.
              # In LiSE this means every change to the world state should happen inside of a call to
              # ``Engine.next_turn`` in a rule.
              if keycache2 and keycache2.rev_gettable(turn):
                  # there's a keycache from a prior turn in this branch. Get it
                  if turn not in keycache2:
                      # since it's not this *exact* turn there might be changes...
                      old_turn = keycache2.rev_before(turn)
                      old_turn_kc = keycache2[turn]
                      added, deleted = get_adds_dels(
                          keys[parentity], branch, turn, tick, stoptime=(
                              branch, old_turn, old_turn_kc.end
                          )
                      )
                      ret = old_turn_kc[old_turn_kc.end].union(added).difference(deleted)
                      # assert ret == get_adds_dels(keys[parentity], branch, turn, tick)[0]  # slow
                      new_turn_kc = WindowDict()
                      new_turn_kc[tick] = ret
                      keycache2[turn] = new_turn_kc
                      return ret
                  if not keycache3:
                      keycache3 = keycache2[turn]
                  if tick not in keycache3:
                      if keycache3.rev_gettable(tick):
                          added, deleted = get_adds_dels(
                              keys[parentity], branch, turn, tick, stoptime=(
                                  branch, turn, keycache3.rev_before(tick)
                              )
                          )
                          ret = keycache3[tick].union(added).difference(deleted)
                          # assert ret == get_adds_dels(keys[parentity], branch, turn, tick)[0]  # slow
                          keycache3[tick] = ret
                          return ret
                      else:
                          turn_before = keycache2.rev_before(turn)
                          tick_before = keycache2[turn_before].end
                          keys_before = keycache2[turn_before][tick_before]
                          added, deleted = get_adds_dels(
                              keys[parentity], branch, turn, tick, stoptime=(
                                  branch, turn_before, tick_before
                              )
                          )
                          ret = keycache3[tick] = keys_before.union(added).difference(deleted)
                          # assert ret == get_adds_dels(keys[parentity], branch, turn, tick)[0]  # slow
                          return ret
                  # assert kcturn[tick] == get_adds_dels(keys[parentity], branch, turn, tick)[0]  # slow
                  return keycache3[tick]
              else:
                  for (parbranch, parturn, partick) in self.db._iter_parent_btt(branch, turn, tick):
                      par_kc_key = parentity + (parbranch,)
                      if par_kc_key in keycache:
                          kcpkc = keycache[par_kc_key]
                          if parturn in kcpkc and kcpkc[parturn].rev_gettable(partick):
                              parkeys = kcpkc[parturn][partick]
                              break
                          elif kcpkc.rev_gettable(parturn-1):
                              partkeys = kcpkc[parturn-1]
                              parkeys = partkeys[partkeys.end]
                              break
                  else:
                      parkeys = frozenset()
                  keycache2 = SettingsTurnDict()
                  added, deleted = get_adds_dels(
                      keys[parentity], branch, turn, tick, stoptime=(
                          parbranch, parturn, partick
                      )
                  )
                  ret = parkeys.union(added).difference(deleted)
                  keycache2[turn] = {tick: ret}
                  keycache[keycache_key] = keycache2
                  # assert ret == get_adds_dels(keys[parentity], branch, turn, tick)[0]  # slow
                  return ret
          ret = frozenset(get_adds_dels(keys[parentity], branch, turn, tick)[0])
          if keycache2:
              if keycache3:
                  keycache3[tick] = ret
              else:
                  keycache2[turn] = {tick: ret}
          else:
              kcc = SettingsTurnDict()
              kcc[turn] = {tick: ret}
              keycache[keycache_key] = kcc
          return ret