Skip to content

Commit

Permalink
docs: unimportant changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
QwQ-dev committed Dec 20, 2024
1 parent 81ec7ba commit 241d47d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 28 deletions.
22 changes: 18 additions & 4 deletions cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ L1 L2 cache module, currently L1 cache has been implemented, L2 cache is still i
The original purpose of this module was to design a L1 cache for the `mongodb` module, but now it is **general-purpose**.

### usage

```kotlin
// Dependencies
dependencies {
// annotation module
compileOnly("me.qwqdev.library:cache:1.0-SNAPSHOT")
}
```

```java
public class Main {
public static void main(String[] args) {
Expand Down Expand Up @@ -34,7 +43,7 @@ public class Main {
MemoryQueryCacheInterface<String, String> memoryQueryCacheInterface = MemoryQueryCacheFactory.create();

// create cache service and bind memory query cache
CacheService<String, String> cacheService = CacheServiceFactory.create(memoryQueryCacheInterface);
L1CacheService<String, String> l1CacheService = L1CacheServiceFactory.create(memoryQueryCacheInterface);

// expiration settings (this is for one element, not the entire map)
ExpirationSettings expirationSettings = ExpirationSettings.of(100, TimeUnit.DAYS);
Expand All @@ -52,10 +61,10 @@ public class Main {
);

// Testing time: 45, db query
cacheService.get("testKey", dbQuery, true, expirationSettings);
l1CacheService.get("testKey", dbQuery, true, expirationSettings);

// Now we query again test L1 cache, Testing time: 0
cacheService.get("testKey", dbQuery, true, expirationSettings);
l1CacheService.get("testKey", dbQuery, true, expirationSettings);
}
}

Expand Down Expand Up @@ -84,6 +93,11 @@ public class MemoryQueryCacheFactory {
}
```

`CacheService` is a key-value pair-based cache service, which needs to be bound to a specific cache implementation,
`L1CacheService` is a key-value pair-based cache service, which needs to be bound to a specific cache implementation,
such as `MemoryQueryCacheInterface`. When the L2 cache is developed, it only needs to change the bound cache implementation, which is different from L1.

### scalability

For more levels of cache, we only need to implement `QueryCacheInterface` to implement something similar to `MemoryQueryCache`. Then create a new Service class and implement `QueryCacheInterface`.

If it is java memory based, we recommend using `MemoryQueryCacheInterface` (L1 cache already exists, so this is actually not necessary).

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.qwqdev.library.cache.factory;

import me.qwqdev.library.cache.service.L1CacheService;
import me.qwqdev.library.cache.service.QueryCacheInterface;

/**
* A factory class for creating instances of L1CacheService.
*
* @since 2024-12-20 15:37
*/
public class L1CacheServiceFactory {
/**
* Creates a L1CacheService with the specified QueryCacheInterface implementation.
*
* @param queryCacheInterface the QueryCacheInterface implementation to be used by the L1CacheService
* @param <K> the type of cache key
* @param <V> the type of cache value
* @return a new instance of L1CacheService
*/
public static <K, V> L1CacheService<K, V> create(QueryCacheInterface<K, V> queryCacheInterface) {
return new L1CacheService<>(queryCacheInterface);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
@Data
@RequiredArgsConstructor
public class CacheService<K, V> implements CacheInterface<K, V> {
public class L1CacheService<K, V> implements CacheInterface<K, V> {
private final QueryCacheInterface<K, V> queryCacheInterface;

/**
Expand Down
8 changes: 8 additions & 0 deletions mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ For the first and second level cache, it is actually implemented in the cache mo

### usage

```kotlin
// Dependencies
dependencies {
// annotation module
compileOnly("me.qwqdev.library:mongodb:1.0-SNAPSHOT")
}
```

We recommend using `MongoDBConnectionFactory` to create connections instead of creating objects directly.

```java
Expand Down

0 comments on commit 241d47d

Please sign in to comment.