1classdef CacheClassSwitcher < StatefulClassSwitcher
2 % A
class switcher section based on cache hits and misses
4 % Copyright (c) 2012-2026, Imperial College London
18 function self = CacheClassSwitcher(
classes, items, capacity, levels)
19 % SELF = CACHECLASSSWITCHER(CLASSES, ITEMS, CAPACITY, LEVELS)
21 if nargin<4 %~exist(
'levels',
'var')
24 self@StatefulClassSwitcher(
classes, 'Cache');
29 self.csFun = @(r, s, state, statep) self.simpleHitMiss(r, s, state, statep); % do nothing by default
30 self.hitClass = sparse([]);
31 self.missClass = sparse([]);
32 self.actualHitProb = sparse([]); % this field
is filled after model solution
33 self.actualMissProb = sparse([]); % this field
is filled after model solution
38 function prob = simpleHitMiss(self, r, s, state, statep)
39 % PROB = SIMPLEHITMISS(R, S, STATE, STATEP)
42 state = []; %local server state
43 statep = []; %local server state
45 if isempty(state) % get csMask (B matrix)
46 if (r==s ... % hit and miss in the cache can depart in the same class
47 || ((r <= length(self.hitClass) && r <= length(self.missClass)) ... % since hitClass and missClass are sparse, check entry for r exists
48 && (s == self.hitClass(r) || s == self.missClass(r)))) ... % route out hit or miss
classes
49 && (~isempty(find(r == self.hitClass)) || ~isempty(find(r == self.missClass))) % don't route out
classes that are not hit or miss
55 % un-comment to restore class-switching in routing
56 % if sum(state) == sum(statep)+1 % hit
57 % if (r <= length(self.hitClass)) && s == self.hitClass(r)
63 % if (r <= length(self.missClass)) && s == self.missClass(r)