When we receive a new model to set in our cache, unbind the tracker from the previous cache object, sync the objects' cids so helpers think they are the same object, save a referance to the object we are tracking, and re-bind our onModify hook.
352213
function(object){
    var target = this.value();
    if(!object || !target || !target.isData || !object.isData){ return void 0; }
    target._cid || (target._cid = target.cid);
    object._cid || (object._cid = object.cid);
    target.cid = object.cid;
    this.tracking = object;
  }
755242
def _update(self, *_):
        """"""
        if getattr(self, '_unlinked', False):
            return
        if getattr(self, '_updating', False):
            return
        self._updating = True
        try:
            setattr(self.target[0], self.target[1], self.transform(
                getattr(self.source[0], self.source[1])
            ))
        finally:
            self._updating = False
653274
def defer_entity_syncing(wrapped, instance, args, kwargs):
    

    # Defer entity syncing while we run our method
    sync_entities.defer = True

    # Run the method
    try:
        return wrapped(*args, **kwargs)

    # After we run the method disable the deferred syncing
    # and sync all the entities that have been buffered to be synced
    finally:
        # Enable entity syncing again
        sync_entities.defer = False

        # Get the models that need to be synced
        model_objs = list(sync_entities.buffer.values())

        # If none is in the model objects we need to sync all
        if None in sync_entities.buffer:
            model_objs = list()

        # Sync the entities that were deferred if any
        if len(sync_entities.buffer):
            sync_entities(*model_objs)

        # Clear the buffer
        sync_entities.buffer = {}
233306
def track(cls, obj, ptr):
        
        cls._objects.add(cls(obj, ptr))
1190626
private void cacheLinkedObject(String owningObjID,
                                   String linkFieldName,
                                   DBObject linkedObject) {
        // Find or create map for the owning object.
        Map<String, Map<String, DBObject>> objMap = m_linkedObjectMap.get(owningObjID);
        if (objMap == null) {
            objMap = new HashMap<String, Map<String, DBObject>>();
            m_linkedObjectMap.put(owningObjID, objMap);
        }
        
        // Find or create map for the link field.
        Map<String, DBObject> linkMap = objMap.get(linkFieldName);
        if (linkMap == null) {
            linkMap = new HashMap<String, DBObject>();
            objMap.put(linkFieldName, linkMap);
        }
        
        // Add the object to the link map.
        linkMap.put(linkedObject.getObjectID(), linkedObject);
    }
1186002
private Object storeCachedObject(K key, CachedObject<V> co) {
		//data is only locked if cleanup removes cached objects
		synchronized (data) {
			data.put(key, co);
		}
		//mirror is also locked if cleanup is busy collecting cached objects
		synchronized (mirror) {
			mirror.put(key, co);
		}
		System.out.println(new LogEntry("object with key " + key + " stored in cache"));
		return co;
	}
894704
def update(obj, meta=nil)
      meta ||= {}
      self.temp_object = TempObject.new(obj, meta['name'])
      self.meta['name'] ||= temp_object.name if temp_object.name
      clear_analyser_cache
      add_meta(obj.meta) if obj.respond_to?(:meta)
      add_meta(meta)
      self
    end
304043
@Override
    protected <T> void unbind(LifecycleManager manager, Class<T> clazz, T object) throws ObjectNotAssociatedException {
        // cancel binding

        Binding binding = STORE.get(clazz);
        if (binding == null) {
            throw new ObjectNotAssociatedException();
        }
        if (!binding.containsKey(object)) {
            throw new ObjectNotAssociatedException();
        }
        binding.remove(object);

        // cancel tracking

        Tracking tracking = TRACK.get(manager);
        tracking.remove(clazz);
    }
859494
function DirectLinkInfo(obj) {
    this.id = obj.tracking_no
    this.state = obj.status
    this.states = obj.states.reverse()
    this.trackerWebsite = directLink.getLink(obj.tracking_no)
}
1183901
def persistent_object_context_changed(self):
        
        super().persistent_object_context_changed()

        def change_registration(registered_object, unregistered_object):
            if registered_object and registered_object.uuid == self.parent_uuid:
                self.__parent = registered_object

        if self.persistent_object_context:
            self.__registration_listener = self.persistent_object_context.registration_event.listen(change_registration)

            self.__parent = self.persistent_object_context.get_registered_object(self.parent_uuid)
1046535
public void cache(Identity oid, Object obj)
    {
        if (oid != null && obj != null)
        {
            ObjectCache cache = getCache(oid, obj, METHOD_CACHE);
            if (cache != null)
            {
                cache.cache(oid, obj);
            }
        }
    }
1019767
@Override
    protected <T> void bind(LifecycleManager manager, Class<T> clazz, T object) throws ObjectAlreadyAssociatedException {
        // update binding
        STORE.putIfAbsent(clazz, new Binding());
        Binding binding = STORE.get(clazz);

        if (binding.put(object, manager) != null) {
            throw new ObjectAlreadyAssociatedException();
        }

        // update tracking
        TRACK.putIfAbsent(manager, new Tracking());
        Tracking tracking = TRACK.get(manager);

        tracking.add(clazz);
    }
1174408
function updateItemUsage(self, oItem) {
			if (self._metadata.__byKey__[oItem.oData.key] != null) { // ItemData already exists, we need to remove the old position index
				var oldIndex = self._metadata.__byKey__[oItem.oData.key];
				delete self._metadata.__byIndex__[oldIndex];
				Log.debug("Cache Manager LRUPersistentCache: set/internalset - item already exists, so its indexes are updated");
			}
			self._metadata.__byIndex__[oItem.oData.lu] = oItem.oData.key;
			self._metadata.__byKey__[oItem.oData.key] = oItem.oData.lu;

			seekMetadataLRU(self);
		}
592965
function() {
      var self = this;

      var previousAttributes = _.clone(this.attributes);

      this.attributes = _.clone(this._serverData);
      Parse._arrayEach(this._opSetQueue, function(opSet) {
        self._applyOpSet(opSet, self.attributes);
        Parse._objectEach(opSet, function(op, key) {
          self._resetCacheForKey(key);
        });
      });

      // Trigger change events for anything that changed because of the fetch.
      Parse._objectEach(previousAttributes, function(oldValue, key) {
        if (self.attributes[key] !== oldValue) {
          self.trigger('change:' + key, self, self.attributes[key], {});
        }
      });
      Parse._objectEach(this.attributes, function(newValue, key) {
        if (!_.has(previousAttributes, key)) {
          self.trigger('change:' + key, self, newValue, {});
        }
      });
    }
1141604
def update_association_cache_for(association, target, action=:add)
    return unless association_cached? association
    case action
    when :add
      return if @association_cache[association].collection.include? target
      @association_cache[association].push(target) # don't use `<<` because overriden method in AssociationCollection gets called instead
    when :delete      
      @association_cache[association].delete target
    end
  end
529461
def _tracker(self, _observer_, _self_, *args, **kwds):
        
        self.track_object(_self_,
                          name=_observer_.name,
                          resolution_level=_observer_.detail,
                          keep=_observer_.keep,
                          trace=_observer_.trace)
        _observer_.init(_self_, *args, **kwds)
685958
private final void setPersNew() {
		status = ObjectState.PERSISTENT_NEW;
		stateFlags = PS_PERSISTENT | PS_TRANSACTIONAL | PS_DIRTY | PS_NEW;
		context.getSession().internalGetCache().notifyDirty(this);
	}