How can we keep only recently configured leaf or replace existing with new?

Assume that I have configured all leaf.

container test{
list ipv4-list {
			key "ipv4addr";
			leaf ipv4addr {  type inet:ipv4-prefix; }
			leaf lid { type yang:counter64 ; }
			leaf glid { type yang:counter64; }
			leaf lsn-lid { type yang:counter64 ; }
			leaf age { type yang:counter64; }

Next time when I configure
case 1:
ipv4addr lid
only ipv4addr and lid and age should be set and rest other should be reset.

case 2:
ipv4addr lid glid
only ipv4addr, lid, glid and age should be set and rest other should be reset.

i.e. at any point, only recent configuration should be present (for first 4 leaf).
Can we put such constrain?

You could use hooks (UG - chapter “Hooks”) to modify running transaction depending on changes explicitly done by user,. Though, please note that this type of auto-configuration of YANG elements may cause issues with higher device management layers, if applicable in your scenarios/use-cases.

It adds sort of extra business-logic that may need to be addressed (user has to realize this when working with config, higher layer network management software can hit out-of-sync configuration state, etc.)