Skip to content

Commit

Permalink
feat(infra,docs): update libs directory and TSC config, add general i…
Browse files Browse the repository at this point in the history
…nfo to readme
  • Loading branch information
zhibirc committed Dec 4, 2023
1 parent 1bb504f commit 5a5fca3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 47 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ If in general it's usually true, this is very subjective if applied to implement

## General Theory

When the cache becomes full, a cache block or record/entry must be evicted to make room for a new block. The replacement policy determines which block to evict.
When the cache becomes full, a cache block or record/entry must be evicted to make room for a new block. The replacement policy determines which block to evict.

Various cache implementations can have slightly different public APIs, however most of them are very consistent in their core capabilities. In the list below there are typical extra features (or just their naming) which can be found in known realisations:

| Member | Type | Description |
|--------|------|-------------------------------------------------------------------------------------|
|`setpop`|method|Sets a value for the given key, but besides that returns evicted object or old value.|
|`peek` |method|Retrieves the value associated with the given key, doesn't update access information.|
19 changes: 1 addition & 18 deletions libs/decorators.ts → libs/decorators/detect-one-hit-wonder.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Cache method decorators.
* Designed to be used to extend cache capabilities.
*/

/**
* Detect one-hit-wonder objects.
*/
Expand Down Expand Up @@ -31,17 +26,5 @@ const detectOneHitWonder = (() => {
}
})();

function log() {
return function (originalMethod: any, _context: ClassMethodDecoratorContext) {
function replacementMethod(this: any, key: any, value: any) {
// @todo: implement
}

return replacementMethod;
};
}


export {
detectOneHitWonder
};
export default detectOneHitWonder;
15 changes: 15 additions & 0 deletions libs/decorators/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Add logging for cache operations.
*/
function log() {
return function (originalMethod: any, _context: ClassMethodDecoratorContext) {
function replacementMethod(this: any, key: any, value: any) {
// @todo: implement
}

return replacementMethod;
};
}


export default log;
22 changes: 0 additions & 22 deletions libs/types.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion libs/types.js

This file was deleted.

6 changes: 2 additions & 4 deletions rr-cache/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TConfigOptions, ICache } from '../libs/types.js';
import { ICache } from '../libs/types.js';

class RRCache implements ICache {
#hits: number;
Expand All @@ -9,9 +9,7 @@ class RRCache implements ICache {
#freeSlots: Array<number>;
#store;

constructor ( options: TConfigOptions ) {
const { capacity } = options;

constructor ( capacity: number ) {
if (!Number.isInteger(capacity) || capacity <= 0) throw new Error('invalid "capacity": positive integer expected');

this.#hits = 0;
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"*/index.ts"
],
"exclude": [
"node_modules"
"node_modules",
"libs"
]
}

0 comments on commit 5a5fca3

Please sign in to comment.