Reporter Plugin question

I’m trying to write new plugin for GlyphsApp, which will use sidebearings for its calculations.
This question appeared, when my early version of plugin proved to be very slow and inefficient:
is there any way to make reporter plugin execute code only if sidebearings-value or nodes of glyphs in active window has changed? For now, reporters are executing code everytime when viewport’s position or scale changes.
for now, my code looks like this:

def background(self, layer):

		sidebearingArea =  self.sidebearingArea()
		print "L: %s" % sidebearingArea['left']
		print "R: %s" % sidebearingArea['right']

def sidebearingArea(self):
		xHeight = Glyphs.font.masters[0].xHeight
		layer = Glyphs.font.selectedLayers[0] # current layer

		leftArea = 0
		rightArea = 0

		for height in range(0,int(xHeight)):
			intersections = layer.intersectionsBetweenPoints((-1000, height), (layer.width + 1000, height))

			leftOneLine  = intersections[1].x
			rightOneLine = layer.width - intersections[-2].x
			leftArea  += leftOneLine
			rightArea += rightOneLine

		leftArea  = int(round(leftArea))
		rightArea = int(round(rightArea))
		areaDict  = {'left' : leftArea, 'right' : rightArea}

		return areaDict


You need to store three things. The sideBearings area, layer itself and the lastOperation of the glyph if the later two change, recalculate, if not, use the stored value.

And to speed it up a bit, you could reduce the number of cuts you do. That would give a bit lower accuracy but it might be ok.

Ok, I will try to implement it. Thanks!