Here is a very basic circuit that would limit the cap voltage to 2.7V.
The zener diode is used so that the 2.7V reference is fairly constant regardless of the battery voltage.
simulate this circuit – Schematic created using CircuitLab
If you use an op-amp as shown, the charging rate will decrease as the cap approaches the reference voltage. If you were to replace the op-amp with a comparator, this shouldn't be an issue. To use a comparator, I believe a pullup resistor would need to be connected from the comparator output to the positive end of the battery.
Here is a simulation that uses an op-amp.