Put the heavy alignment ranges calculation called on demand and then cached
4470
def alignment_ranges(self):
     """"""
     if not self.is_aligned(): raise ValueError("you can't get alignment ranges from something that didn't align")
     if self._alignment_ranges: return self._alignment_ranges
     self._alignment_ranges = self._get_alignment_ranges()
     return self._alignment_ranges
416521
def cached(fn, size=32):
    ''' '''
    assert callable(fn)
    assert isinstance(size, int)
    return overload(fn)(lru_cache(size, typed=True)(fn))
759211
protected boolean computeOffset(final int dataIndex, CacheDataSet cache) {
        float layoutOffset = getLayoutOffset();
        int pos = cache.getPos(dataIndex);
        float startDataOffset = Float.NaN;
        float endDataOffset = Float.NaN;
        if (pos > 0) {
            int id = cache.getId(pos - 1);
            if (id != -1) {
                startDataOffset = cache.getEndDataOffset(id);
                if (!Float.isNaN(startDataOffset)) {
                    endDataOffset = cache.setDataAfter(dataIndex, startDataOffset);
                }
            }
        } else if (pos == 0) {
            int id = cache.getId(pos + 1);
            if (id != -1) {
                endDataOffset = cache.getStartDataOffset(id);
                if (!Float.isNaN(endDataOffset)) {
                    startDataOffset = cache.setDataBefore(dataIndex, endDataOffset);
                }
            } else {
                startDataOffset = getStartingOffset((cache.getTotalSizeWithPadding()));
                endDataOffset = cache.setDataAfter(dataIndex, startDataOffset);
            }
        }

        Log.d(LAYOUT, TAG, "computeOffset [%d, %d]: startDataOffset = %f endDataOffset = %f",
                dataIndex, pos, startDataOffset, endDataOffset);

        boolean inBounds = !Float.isNaN(cache.getDataOffset(dataIndex)) &&
                endDataOffset > layoutOffset &&
                startDataOffset < -layoutOffset;

        return inBounds;
    }
1247251
private final void forceRebuildDirtyCache() {
    final long[] tgtArr = new long[1 << lgArrLongs_];
    curCount_ = HashOperations.hashArrayInsert(cache_, tgtArr, lgArrLongs_, thetaLong_);
    cache_ = tgtArr;
    dirty_ = false;
    //hashTableThreshold stays the same
  }
545972
void computeAverageQ(Cache cache) {
		float[] weights = cache.weights.data;
		cache.aveQ.set(0,0);

		for (int i = 0; i < controls.size(); i++) {
			Control c = controls.get(i);
			float w = weights[i];
			cache.aveQ.x += c.q.x * w;
			cache.aveQ.y += c.q.y * w;
		}
		cache.aveQ.x /= cache.totalWeight;
		cache.aveQ.y /= cache.totalWeight;
	}
338331
function set ( text, results ) {
	cache.push({
		text: trim(text),
		results: results
	});
}
8591
def mul_block(self, index, val):
        """"""
        self._prepare_cache_slice(index)
        self.msinds[self.cache_slice] *= val
1332821
def _fill_cache(self, num=None):
        
        if self._iter:
            try:
                for i in range(num or ITER_CHUNK_SIZE):
                    self._result_cache.append(next(self._iter))
            except StopIteration:
                self._iter = None
133754
def _init_offsets(self, batchsize):
        
        upper_offsets = previous_lower_offsets = self._lower_offsets
        if not upper_offsets:
            upper_offsets = self.latest_offsets
        self._upper_offsets = {p: o for p, o in upper_offsets.items() if o > self._min_lower_offsets[p]}

        # remove db dupes not used anymore
        if self._dupes:
            for p in list(six.iterkeys(self._dupes)):
                if p not in self._upper_offsets:
                    db = self._dupes.pop(p)
                    db.close()
                    os.remove(db.filename)

        partition_batchsize = 0
        if self._upper_offsets:
            partition_batchsize = max(int(batchsize * self.__scan_excess), batchsize)
            self._lower_offsets = self._upper_offsets.copy()
            total_offsets_run = 0
            for p in sorted(self._upper_offsets.keys()):
                # readjust partition_batchsize when a partition scan starts from latest offset
                if total_offsets_run > 0 and partition_batchsize > batchsize:
                    partition_batchsize = batchsize
                if partition_batchsize > 0:
                    self._lower_offsets[p] = max(self._upper_offsets[p] - partition_batchsize, self._min_lower_offsets[p])
                    offsets_run = self._upper_offsets[p] - self._lower_offsets[p]
                    total_offsets_run += offsets_run
                    partition_batchsize = partition_batchsize - offsets_run
                else:
                    break
            log.info('Offset run: %d', total_offsets_run)
            # create new consumer if partition list changes
            if previous_lower_offsets is not None and set(previous_lower_offsets.keys()) != set(self._lower_offsets):
                self._create_scan_consumer(self._lower_offsets.keys())

            # consumer must restart from newly computed lower offsets
            self._update_offsets(self._lower_offsets)
        log.info('Initial offsets for topic %s: %s', self._topic, repr(self._lower_offsets))
        log.info('Target offsets for topic %s: %s', self._topic, repr(self._upper_offsets))

        return batchsize
61757
def refresh_committed_offsets_if_needed(self):
        """"""
        if self._subscription.needs_fetch_committed_offsets:
            offsets = self.fetch_committed_offsets(self._subscription.assigned_partitions())
            for partition, offset in six.iteritems(offsets):
                # verify assignment is still active
                if self._subscription.is_assigned(partition):
                    self._subscription.assignment[partition].committed = offset.offset
            self._subscription.needs_fetch_committed_offsets = False
85634
def add_to_cache(self, cache_id, inputs, output):
        """"""
        self.inputs_changed[cache_id] = False
        self.cached_outputs[cache_id] = output
        self.order.append(cache_id)
        self.cached_inputs[cache_id] = inputs
        for a in inputs:
            if a is not None and not isinstance(a, Number) and not isinstance(a, str):
                ind_id = self.id(a)
                v = self.cached_input_ids.get(ind_id, [weakref.ref(a), []])
                v[1].append(cache_id)
                if len(v[1]) == 1:
                    a.add_observer(self, self.on_cache_changed)
                self.cached_input_ids[ind_id] = v
1023758
public void cache(K name, V data) {

		if ( data == null){
			return;
		}
		if ( serializedCache != null){


			logger.debug("Caching {}  {}", name, data);

			serializedCache.put(name,data);


			// every 1000 objects we are writing to disk
			if ( serializedCache.keySet().size() % 1000 == 0 ) {

				flushCache();

			}

		}


	}
97115
def cache_items(values):
    """"""
    import os
    config_path = os.path.expanduser('~/.config/blockade')
    file_path = os.path.join(config_path, 'cache.txt')
    if not os.path.isfile(file_path):
        file(file_path, 'w').close()
    written = [x.strip() for x in open(file_path, 'r').readlines()]
    handle = open(file_path, 'a')
    for item in values:
        # Because of the option to submit in clear or hashed, we need to make
        # sure we're not re-hashing before adding.
        if is_hashed(item):
            hashed = item
        else:
            hashed = hash_values(item)

        if hashed in written:
            continue
        handle.write(hashed + "\n")
    handle.close()
    return True
1057768
public void cache(Class<?> cls) {
        if (cls != null) {
            classes.put(cls.getName(), new SoftReference<Class<?>>(cls));
        }
    }
635917
def memoize_method(method):
    """"""
    cache = {}

    @functools.wraps(method)
    def wrapper(self, *args, **kwargs):
        """Caching wrapper."""
        key = (args, tuple(sorted(kwargs.items())))
        if key in cache:
            return cache[key]
        else:
            result = method(self, *args, **kwargs)
            cache[key] = result
            return result

    return wrapper
1220268
def _write_to_cache(self, expr, res):
        """"""
        res = dedent(res)
        super()._write_to_cache(expr, res)
415080
def _set_as_cached(self, item, cacher):
        
        self._cacher = (item, weakref.ref(cacher))