Class Cache
-
- All Implemented Interfaces:
-
java.io.Serializable
,jline.lang.Copyable
public class Cache extends StatefulNode implements Serializable
A cache node that implements cache replacement policies and class switching based on cache hits and misses.
The Cache node models a caching system where incoming jobs request items from a finite cache. When a requested item is found in the cache (hit), the job may be routed to one class; when the item is not found (miss), it may be routed to a different class. This enables modeling of cache-aware queueing networks where performance depends on cache hit rates.
Key features:
- Multi-level cache support with configurable capacity per level
- Various replacement strategies (LRU, FIFO, RANDOM, etc.)
- Popularity-based item access patterns (e.g., Zipf distribution)
- Class switching based on hit/miss outcomes
- Optional graph-based cache structures
- Since:
1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
Cache.PopularityKey
A key class for storing popularity distributions in a 2D coordinate system.
Used internally to map (item class, job class) pairs to their popularity distributions.
-
Field Summary
Fields Modifier and Type Field Description public final ItemSet
items
public final Matrix
itemLevelCap
public final Array<Matrix>
graph
public final CacheClassSwitcher
cacheServer
public Array<Array<Matrix>>
accessProb
protected SchedStrategyType
schedPolicy
protected SchedStrategy
schedStrategy
public Matrix
state
public Matrix
statePrior
public final NodeAttribute
attribute
public Network
model
protected InputSection
input
protected OutputSection
output
protected ServiceSection
server
protected DropStrategy
dropStrategy
protected int
statefulIdx
protected int
nodeIndex
protected int
stationIdx
protected String
name
-
Constructor Summary
Constructors Constructor Description Cache(Network model, String name, int nitems, int itemLevelCap, ReplacementStrategy replPolicy)
Creates a single-level cache with the specified item capacity and replacement policy. Cache(Network model, String name, int nitems, int itemLevelCap, ReplacementStrategy replPolicy, Array<Matrix> graph)
Creates a single-level cache with the specified item capacity, replacement policy, and graph structure. Cache(Network model, String name, int nitems, Matrix itemLevelCap, ReplacementStrategy replPolicy)
Creates a multi-level cache with different capacities per level and a replacement policy. Cache(Network model, String name, int nitems, Matrix itemLevelCap, ReplacementStrategy replPolicy, Array<Matrix> graph)
Creates a multi-level cache with different capacities per level, replacement policy, and graph structure.
-
Method Summary
Modifier and Type Method Description ItemSet
getItems()
Gets the set of items that can be stored in this cache. Matrix
getItemLevelCap()
Gets the capacity configuration for each cache level. Array<Matrix>
getGraph()
Gets the graph structure defining the cache organization. CacheClassSwitcher
getCacheServer()
Gets the internal cache server that handles class switching logic. Matrix
getAccessProb(int i, int j)
Gets the access probability matrix for a specific cache level and job class. Matrix
getHitClass()
For an incoming job of class r, HITCLASS[r] is the new class of that job after a hit Matrix
getHitRatio()
Gets the actual hit probability/ratio for each job class. Matrix
getMissClass()
For an incoming job of class r, MISSCLASS[r] is the new class of that job after a miss Matrix
getMissRatio()
Gets the actual miss probability/ratio for each job class. int
getNumberOfItems()
Gets the total number of items that can be requested from this cache. ReplacementStrategy
getReplacementStrategy()
Gets the replacement strategy used when the cache is full. List<Section>
getSections()
Gets the internal sections of this cache node. int
getnLevels()
Gets the number of cache levels. Distribution
popularityGet(int i)
Gets the popularity distribution for a linear index. Distribution
popularityGet(int i, int j)
Gets the popularity distribution for a specific item class and job class. int
popularityLength()
Gets the maximum dimension of the popularity matrix. void
popularitySet(int i, Distribution o)
Sets the popularity distribution for a linear index. void
popularitySet(int i, int j, Distribution o)
Sets the popularity distribution for a specific item class and job class. void
reset()
Resets the internal data structures when the network model is reset. void
setAccessProb(Array<Array<Matrix>> R)
Sets the access probability matrices for all cache levels and job classes. void
setHitClass(JobClass jobinclass, JobClass joboutclass)
Sets the output class for jobs that experience a cache hit. void
setMissClass(JobClass jobinclass, JobClass joboutclass)
Sets the output class for jobs that experience a cache miss. void
setProbRouting(JobClass jobClass, Node destination, double probability)
Sets probabilistic routing for a job class to a destination node. void
setRead(JobClass jobClass, Distribution distribution)
Sets the read policy for a job class using a popularity distribution. void
setReadItemEntry(JobClass jobClass, Distribution popularity, int cardinality)
Sets the read policy for a job class with explicit item cardinality. void
setResultHitProb(Matrix actualHitProb)
Sets the actual hit probabilities from simulation or analysis results. void
setResultMissProb(Matrix actualMissProb)
Sets the actual miss probabilities from simulation or analysis results. void
setScheduling(int jobClass, SchedStrategy strategy)
Sets the scheduling strategy for a job class. -
Methods inherited from class jline.lang.nodes.StatefulNode
clearState, getNumberOfServers, getState, getStatePrior, getStateSpace, getStatefulIndex, resetStateSpace, setState, setState, setStatePrior, setStateSpace
-
Methods inherited from class jline.lang.nodes.Node
getAttribute, getCap, getClassCap, getDropStrategy, getInput, getModel, getNodeIndex, getOutput, getOutputStrategies, getRoutingStrategy, getServer, getStatefulIdx, getStationIdx, isReferenceStation, isStateful, printSummary, resetRouting, setModel, setNodeIdx, setRouting, setRouting, setStationIdx
-
Methods inherited from class jline.lang.Element
getName, setName
-
Methods inherited from class jline.lang.Copyable
copy
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
Cache
Cache(Network model, String name, int nitems, int itemLevelCap, ReplacementStrategy replPolicy)
Creates a single-level cache with the specified item capacity and replacement policy.- Parameters:
model
- The network model this cache belongs toname
- The name of the cache nodenitems
- The total number of items that can be requested from this cacheitemLevelCap
- The capacity of the cache (number of items it can hold)replPolicy
- The replacement strategy to use when the cache is full
-
Cache
Cache(Network model, String name, int nitems, int itemLevelCap, ReplacementStrategy replPolicy, Array<Matrix> graph)
Creates a single-level cache with the specified item capacity, replacement policy, and graph structure.- Parameters:
model
- The network model this cache belongs toname
- The name of the cache nodenitems
- The total number of items that can be requested from this cacheitemLevelCap
- The capacity of the cache (number of items it can hold)replPolicy
- The replacement strategy to use when the cache is fullgraph
- Optional graph structure defining cache organization
-
Cache
Cache(Network model, String name, int nitems, Matrix itemLevelCap, ReplacementStrategy replPolicy)
Creates a multi-level cache with different capacities per level and a replacement policy.- Parameters:
model
- The network model this cache belongs toname
- The name of the cache nodenitems
- The total number of items that can be requested from this cacheitemLevelCap
- A matrix specifying the capacity of each cache levelreplPolicy
- The replacement strategy to use when the cache is full
-
Cache
Cache(Network model, String name, int nitems, Matrix itemLevelCap, ReplacementStrategy replPolicy, Array<Matrix> graph)
Creates a multi-level cache with different capacities per level, replacement policy, and graph structure.- Parameters:
model
- The network model this cache belongs toname
- The name of the cache nodenitems
- The total number of items that can be requested from this cacheitemLevelCap
- A matrix specifying the capacity of each cache levelreplPolicy
- The replacement strategy to use when the cache is fullgraph
- Optional graph structure defining cache organization
-
-
Method Detail
-
getItems
ItemSet getItems()
Gets the set of items that can be stored in this cache.
- Returns:
The ItemSet object managing the cache items
-
getItemLevelCap
Matrix getItemLevelCap()
Gets the capacity configuration for each cache level.
- Returns:
A matrix where each element specifies the item capacity of a cache level
-
getGraph
Array<Matrix> getGraph()
Gets the graph structure defining the cache organization.
- Returns:
Array of matrices representing the cache graph structure, or null if not defined
-
getCacheServer
CacheClassSwitcher getCacheServer()
Gets the internal cache server that handles class switching logic.
- Returns:
The CacheClassSwitcher instance managing hit/miss class transitions
-
getAccessProb
Matrix getAccessProb(int i, int j)
Gets the access probability matrix for a specific cache level and job class.
- Parameters:
i
- The cache level indexj
- The job class index- Returns:
The access probability matrix for the specified indices
-
getHitClass
Matrix getHitClass()
For an incoming job of class r, HITCLASS[r] is the new class of that job after a hit
- Returns:
- the matrix of hit classes
-
getHitRatio
Matrix getHitRatio()
Gets the actual hit probability/ratio for each job class.
This returns the observed hit rates from simulation or analysis, not the theoretical expected values.
- Returns:
A matrix containing the hit ratio for each job class
-
getMissClass
Matrix getMissClass()
For an incoming job of class r, MISSCLASS[r] is the new class of that job after a miss
- Returns:
- the matrix of miss classes
-
getMissRatio
Matrix getMissRatio()
Gets the actual miss probability/ratio for each job class.
This returns the observed miss rates from simulation or analysis, not the theoretical expected values.
- Returns:
A matrix containing the miss ratio for each job class
-
getNumberOfItems
int getNumberOfItems()
Gets the total number of items that can be requested from this cache.
- Returns:
The number of distinct items in the item set
-
getReplacementStrategy
ReplacementStrategy getReplacementStrategy()
Gets the replacement strategy used when the cache is full.
- Returns:
The cache replacement strategy (e.g., LRU, FIFO, RANDOM)
-
getSections
List<Section> getSections()
Gets the internal sections of this cache node.
Returns the three main sections: input buffer, cache server, and output dispatcher.
- Returns:
A list containing the input, server, and output sections
-
getnLevels
int getnLevels()
Gets the number of cache levels.
- Returns:
The number of levels in this multi-level cache
-
popularityGet
Distribution popularityGet(int i)
Gets the popularity distribution for a linear index.
Converts a linear index to 2D coordinates and retrieves the distribution.
- Parameters:
i
- The linear index- Returns:
The popularity distribution at the specified index
-
popularityGet
Distribution popularityGet(int i, int j)
Gets the popularity distribution for a specific item class and job class.
- Parameters:
i
- The item class indexj
- The job class index- Returns:
The popularity distribution, or null if not set
-
popularityLength
int popularityLength()
Gets the maximum dimension of the popularity matrix.
- Returns:
The maximum of rows and columns in the popularity matrix
-
popularitySet
void popularitySet(int i, Distribution o)
Sets the popularity distribution for a linear index.
Converts a linear index to 2D coordinates and sets the distribution.
- Parameters:
i
- The linear indexo
- The popularity distribution to set
-
popularitySet
void popularitySet(int i, int j, Distribution o)
Sets the popularity distribution for a specific item class and job class.
Automatically expands the popularity matrix dimensions if necessary.
- Parameters:
i
- The item class indexj
- The job class indexo
- The popularity distribution to set
-
reset
void reset()
Resets the internal data structures when the network model is reset.
Clears the actual hit and miss probability matrices to prepare for a new simulation or analysis run.
-
setAccessProb
void setAccessProb(Array<Array<Matrix>> R)
Sets the access probability matrices for all cache levels and job classes.
- Parameters:
R
- A 2D array of matrices containing access probabilities
-
setHitClass
void setHitClass(JobClass jobinclass, JobClass joboutclass)
Sets the output class for jobs that experience a cache hit.
When a job of class jobinclass hits in the cache, it will be transformed to class joboutclass.
- Parameters:
jobinclass
- The incoming job classjoboutclass
- The job class after a cache hit
-
setMissClass
void setMissClass(JobClass jobinclass, JobClass joboutclass)
Sets the output class for jobs that experience a cache miss.
When a job of class jobinclass misses in the cache, it will be transformed to class joboutclass.
- Parameters:
jobinclass
- The incoming job classjoboutclass
- The job class after a cache miss
-
setProbRouting
void setProbRouting(JobClass jobClass, Node destination, double probability)
Sets probabilistic routing for a job class to a destination node.
- Parameters:
jobClass
- The job class to configure routing fordestination
- The destination nodeprobability
- The routing probability
-
setRead
void setRead(JobClass jobClass, Distribution distribution)
Sets the read policy for a job class using a popularity distribution.
The distribution determines which items are requested by jobs of this class. Common distributions include Zipf for modeling popularity skew.
- Parameters:
jobClass
- The job class to configuredistribution
- The discrete popularity distribution over items
-
setReadItemEntry
void setReadItemEntry(JobClass jobClass, Distribution popularity, int cardinality)
Sets the read policy for a job class with explicit item cardinality.
Similar to setRead but allows specifying the number of items explicitly, useful when the distribution needs to be configured with a specific cardinality.
- Parameters:
jobClass
- The job class to configurepopularity
- The discrete popularity distributioncardinality
- The number of items in the distribution support
-
setResultHitProb
void setResultHitProb(Matrix actualHitProb)
Sets the actual hit probabilities from simulation or analysis results.
- Parameters:
actualHitProb
- Matrix containing the observed hit probabilities
-
setResultMissProb
void setResultMissProb(Matrix actualMissProb)
Sets the actual miss probabilities from simulation or analysis results.
- Parameters:
actualMissProb
- Matrix containing the observed miss probabilities
-
setScheduling
void setScheduling(int jobClass, SchedStrategy strategy)
Sets the scheduling strategy for a job class.
Note: Currently this method has no implementation as caches use FCFS scheduling.
- Parameters:
jobClass
- The job class indexstrategy
- The scheduling strategy (unused)
-
-