The 21-year-old's chances of claiming the number one jersey this season were boosted by the release of former regular shot-stopper Marcus Hahnemann, who joined Wolves on Wednesday.
Hamer played 49 games for League Two champions Brentford last season before claiming the Puma Golden Glove award for keeping the
most clean sheets in the division.
The youngster has already made 115 career appearances, including loan spells with Brentford and Crawley.
Director of football Nick Hammond told the club's official website: "We are delighted Ben is committing himself to us with this new contract.
"Ben has a lot of Football League experience under his belt for such a young goalkeeper. After his loans he now comes back to us to be very much part of our plans for next season and to contest for the jersey."