├── .gitattributes
├── ballerina
├── icon.png
├── CompilerPlugin.toml
├── Ballerina.toml
├── cache_errors.bal
├── README.md
├── Dependencies.toml
├── abstract_cache.bal
├── build.gradle
├── cache.bal
└── tests
│ └── test.bal
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── load-tests
└── order_management_service
│ ├── deployment
│ ├── kustomization.yaml
│ └── ingress.yaml
│ ├── src
│ ├── Ballerina.toml
│ ├── Cloud.toml
│ ├── resources
│ │ └── order_service
│ │ │ ├── public.crt
│ │ │ └── private.key
│ ├── order_service.bal
│ └── client_service.bal
│ └── scripts
│ ├── run.sh
│ └── http-post-request.jmx
├── compiler-plugin-tests
├── src
│ └── test
│ │ ├── resources
│ │ ├── diagnostics
│ │ │ ├── sample1
│ │ │ │ ├── Ballerina.toml
│ │ │ │ └── main.bal
│ │ │ ├── sample2
│ │ │ │ ├── Ballerina.toml
│ │ │ │ └── main.bal
│ │ │ ├── sample3
│ │ │ │ ├── Ballerina.toml
│ │ │ │ └── main.bal
│ │ │ ├── sample4
│ │ │ │ ├── Ballerina.toml
│ │ │ │ └── main.bal
│ │ │ ├── sample5
│ │ │ │ ├── Ballerina.toml
│ │ │ │ └── main.bal
│ │ │ ├── sample6
│ │ │ │ ├── Ballerina.toml
│ │ │ │ └── modules
│ │ │ │ │ ├── config
│ │ │ │ │ └── config.bal
│ │ │ │ │ └── code
│ │ │ │ │ └── code.bal
│ │ │ └── sample7
│ │ │ │ ├── Ballerina.toml
│ │ │ │ └── main.bal
│ │ └── testng.xml
│ │ └── java
│ │ └── io
│ │ └── ballerina
│ │ └── stdlib
│ │ └── cache
│ │ └── compiler
│ │ └── CompilerPluginTest.java
└── build.gradle
├── codecov.yml
├── .github
├── pull_request_template.md
├── CODEOWNERS
└── workflows
│ ├── trivy-scan.yml
│ ├── pull-request.yml
│ ├── build-timestamped-master.yml
│ ├── publish-release.yml
│ ├── fossa_scan.yml
│ ├── process-load-test-result.yml
│ ├── central-publish.yml
│ ├── trigger-load-tests.yml
│ ├── build-with-bal-test-graalvm.yml
│ └── update_specs.yml
├── gradle.properties
├── .gitignore
├── spotbugs-exclude.xml
├── native
├── src
│ ├── main
│ │ └── java
│ │ │ ├── module-info.java
│ │ │ └── io
│ │ │ └── ballerina
│ │ │ └── stdlib
│ │ │ └── cache
│ │ │ └── nativeimpl
│ │ │ ├── concurrentlinkedhashmap
│ │ │ ├── Weigher.java
│ │ │ ├── Linked.java
│ │ │ ├── Weighers.java
│ │ │ ├── LinkedDeque.java
│ │ │ └── ConcurrentLinkedHashMap.java
│ │ │ └── Cache.java
│ └── test
│ │ ├── resources
│ │ └── testng.xml
│ │ └── java
│ │ └── io
│ │ └── ballerina
│ │ └── stdlib
│ │ └── cache
│ │ └── CacheTest.java
├── spotbugs-exclude.xml
└── build.gradle
├── compiler-plugin
├── src
│ └── main
│ │ └── java
│ │ ├── module-info.java
│ │ └── io
│ │ └── ballerina
│ │ └── stdlib
│ │ └── cache
│ │ └── compiler
│ │ ├── CacheCompilerPlugin.java
│ │ ├── CacheCodeAnalyzer.java
│ │ ├── Constants.java
│ │ ├── DiagnosticsCodes.java
│ │ └── CacheConfigValidator.java
└── build.gradle
├── changelog.md
├── settings.gradle
├── gradlew.bat
├── docs
└── spec
│ └── spec.md
├── README.md
├── gradlew
└── LICENSE
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Ensure all Java files use LF.
2 | *.java eol=lf
3 |
--------------------------------------------------------------------------------
/ballerina/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-cache/HEAD/ballerina/icon.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-cache/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/load-tests/order_management_service/deployment/kustomization.yaml:
--------------------------------------------------------------------------------
1 | resources:
2 | - order_management_service.yaml
3 | - ingress.yaml
4 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample1/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "cache_test"
3 | name = "sample1"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample2/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "cache_test"
3 | name = "sample2"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample3/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "cache_test"
3 | name = "sample3"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample4/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "cache_test"
3 | name = "sample4"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample5/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "cache_test"
3 | name = "sample5"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample6/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "cache_test"
3 | name = "sample6"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample7/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "cache_test"
3 | name = "sample7"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | ignore:
2 | - "load-tests"
3 |
4 | coverage:
5 | precision: 2
6 | round: down
7 | range: "60...80"
8 | status:
9 | project:
10 | default:
11 | target: 80
12 |
--------------------------------------------------------------------------------
/load-tests/order_management_service/src/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "cache"
3 | name = "order_management_service"
4 | version = "1.0.0"
5 |
6 | [build-options]
7 | observabilityIncluded = false
8 | cloud = "k8s"
9 |
--------------------------------------------------------------------------------
/ballerina/CompilerPlugin.toml:
--------------------------------------------------------------------------------
1 | [plugin]
2 | id = "cache-compiler-plugin"
3 | class = "io.ballerina.stdlib.cache.compiler.CacheCompilerPlugin"
4 |
5 | [[dependency]]
6 | path = "../compiler-plugin/build/libs/cache-compiler-plugin-3.10.0.jar"
7 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | ## Examples
4 |
5 | ## Checklist
6 | - [ ] Linked to an issue
7 | - [ ] Updated the changelog
8 | - [ ] Added tests
9 | - [ ] Updated the spec
10 | - [ ] Checked native-image compatibility
11 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Lines starting with '#' are comments.
2 | # Each line is a file pattern followed by one or more owners.
3 |
4 | # See: https://help.github.com/articles/about-codeowners/
5 |
6 | # These owners will be the default owners for everything in the repo.
7 | * @NipunaRanasinghe @ayeshLK @shafreenAnfar
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/load-tests/order_management_service/src/Cloud.toml:
--------------------------------------------------------------------------------
1 | [container.image]
2 | repository="ballerina"
3 | name="order_management_service"
4 |
5 | [cloud.deployment]
6 | min_memory="256Mi"
7 | max_memory="512Mi"
8 | min_cpu="200m"
9 | max_cpu="1000m"
10 |
11 | [cloud.deployment.autoscaling]
12 | min_replicas=1
13 | max_replicas=1
14 |
--------------------------------------------------------------------------------
/.github/workflows/trivy-scan.yml:
--------------------------------------------------------------------------------
1 | name: Trivy
2 |
3 | on:
4 | workflow_dispatch:
5 | schedule:
6 | - cron: "30 20 * * *"
7 |
8 | jobs:
9 | call_workflow:
10 | name: Run Trivy Scan Workflow
11 | if: ${{ github.repository_owner == 'ballerina-platform' }}
12 | uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main
13 | secrets: inherit
14 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.caching=true
2 | group=io.ballerina.stdlib
3 | version=3.10.1-SNAPSHOT
4 | ballerinaLangVersion=2201.12.0
5 | stdlibTaskVersion=2.7.0
6 | stdlibTimeVersion=2.7.0
7 | stdlibConstraintVersion=1.7.0
8 |
9 | puppycrawlCheckstyleVersion=10.12.0
10 | ballerinaGradlePluginVersion=2.3.0
11 | testngVersion=7.6.1
12 | jacocoVersion=0.8.10
13 | spotbugsPluginVersion=6.0.18
14 | shadowJarPluginVersion=8.1.1
15 | downloadPluginVersion=5.4.0
16 | releasePluginVersion=2.8.0
17 |
--------------------------------------------------------------------------------
/.github/workflows/pull-request.yml:
--------------------------------------------------------------------------------
1 | name: PR Build
2 |
3 | concurrency:
4 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
5 | cancel-in-progress: true
6 |
7 | on: [pull_request]
8 |
9 | jobs:
10 | call_workflow:
11 | name: Run PR Build Workflow
12 | if: ${{ github.repository_owner == 'ballerina-platform' }}
13 | uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main
14 | secrets: inherit
15 |
--------------------------------------------------------------------------------
/.github/workflows/build-timestamped-master.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | paths-ignore:
8 | - "*.md"
9 | - "docs/**"
10 | - "load-tests/**"
11 | workflow_dispatch:
12 |
13 | jobs:
14 | call_workflow:
15 | name: Run Build Workflow
16 | if: ${{ github.repository_owner == 'ballerina-platform' }}
17 | uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main
18 | secrets: inherit
19 |
--------------------------------------------------------------------------------
/.github/workflows/publish-release.yml:
--------------------------------------------------------------------------------
1 | name: Publish Release
2 |
3 | on:
4 | workflow_dispatch:
5 | repository_dispatch:
6 | types: [stdlib-release-pipeline]
7 |
8 | jobs:
9 | call_workflow:
10 | name: Run Release Workflow
11 | if: ${{ github.repository_owner == 'ballerina-platform' }}
12 | uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main
13 | secrets: inherit
14 | with:
15 | package-name: cache
16 | package-org: ballerina
17 |
--------------------------------------------------------------------------------
/.github/workflows/fossa_scan.yml:
--------------------------------------------------------------------------------
1 | name: Fossa Scan
2 | on:
3 | workflow_dispatch:
4 | schedule:
5 | - cron: '30 18 * * *' # 00:00 in LK time (GMT+5:30)
6 | jobs:
7 | fossa-scan:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v3
11 | - uses: fossas/fossa-action@main
12 | env:
13 | packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
14 | packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
15 | with:
16 | api-key: ${{secrets.FOSSA_APIKEY}}
17 |
--------------------------------------------------------------------------------
/load-tests/order_management_service/deployment/ingress.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: networking.k8s.io/v1
3 | kind: Ingress
4 | metadata:
5 | name: order-management-service
6 | annotations:
7 | kubernetes.io/ingress.class: nginx
8 | spec:
9 | rules:
10 | - host: bal.perf.test
11 | http:
12 | paths:
13 | - path: "/"
14 | pathType: Prefix
15 | backend:
16 | service:
17 | name: order-managemen
18 | port:
19 | number: 9098
20 |
--------------------------------------------------------------------------------
/ballerina/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "ballerina"
3 | name = "cache"
4 | version = "3.10.0"
5 | authors = ["Ballerina"]
6 | keywords = ["cache", "LRU"]
7 | repository = "https://github.com/ballerina-platform/module-ballerina-cache"
8 | icon = "icon.png"
9 | license = ["Apache-2.0"]
10 | distribution = "2201.12.0"
11 |
12 | [platform.java21]
13 | graalvmCompatible = true
14 |
15 | [[platform.java21.dependency]]
16 | groupId = "io.ballerina.stdlib"
17 | artifactId = "cache-native"
18 | version = "3.10.0"
19 | path = "../native/build/libs/cache-native-3.10.0.jar"
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | build
26 | .gradle/
27 | target
28 | # IDEA Files
29 | .idea/
30 | *.iml
31 | *.ipr
32 | *.iws
33 |
34 | # MacOS
35 | *.DS_Store
36 |
37 | # Ballerina
38 | velocity.log*
39 | *Ballerina.lock
40 |
--------------------------------------------------------------------------------
/.github/workflows/process-load-test-result.yml:
--------------------------------------------------------------------------------
1 | name: Process load test results
2 |
3 | on:
4 | repository_dispatch:
5 | types: [cache-load-test]
6 |
7 | jobs:
8 | call_stdlib_process_load_test_results_workflow:
9 | name: Run StdLib Process Load Test Results Workflow
10 | uses: ballerina-platform/ballerina-library/.github/workflows/process-load-test-results-template.yml@main
11 | with:
12 | results: ${{ toJson(github.event.client_payload.results) }}
13 | secrets:
14 | ballerina_bot_token: ${{ secrets.BALLERINA_BOT_TOKEN }}
15 | ballerina_reviewer_bot_token: ${{ secrets.BALLERINA_REVIEWER_BOT_TOKEN }}
16 |
--------------------------------------------------------------------------------
/.github/workflows/central-publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish to the Ballerina central
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | environment:
7 | type: choice
8 | description: Select Environment
9 | required: true
10 | options:
11 | - DEV CENTRAL
12 | - STAGE CENTRAL
13 |
14 | jobs:
15 | call_workflow:
16 | name: Run Central Publish Workflow
17 | if: ${{ github.repository_owner == 'ballerina-platform' }}
18 | uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main
19 | secrets: inherit
20 | with:
21 | environment: ${{ github.event.inputs.environment }}
22 |
--------------------------------------------------------------------------------
/spotbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample5/main.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/cache;
18 |
19 | cache:Cache httpClientCache = new;
20 |
--------------------------------------------------------------------------------
/native/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | module io.ballerina.stdlib.cache {
20 | requires io.ballerina.runtime;
21 | exports io.ballerina.stdlib.cache.nativeimpl;
22 | }
23 |
--------------------------------------------------------------------------------
/compiler-plugin/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | module io.ballerina.stdlib.cache.compiler {
20 | requires io.ballerina.lang;
21 | requires io.ballerina.tools.api;
22 | requires io.ballerina.parser;
23 | }
24 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample6/modules/config/config.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | public const int CAPACITY = 10;
18 | public const float EVICTION_FACTOR = 0.2;
19 | public const decimal DEFAULT_MAX_AGE = 30;
20 | public const decimal CLEANUP_INTERVAL = 60;
21 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample6/modules/code/code.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/cache;
18 | import sample6.config;
19 |
20 | final cache:CacheConfig cacheConfig = {
21 | capacity: 10,
22 | evictionFactor: config:EVICTION_FACTOR,
23 | defaultMaxAge: config:DEFAULT_MAX_AGE,
24 | cleanupInterval: config:CLEANUP_INTERVAL
25 | };
26 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample2/main.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/cache;
18 |
19 | public function main() returns error? {
20 |
21 | cache:Cache cache = new(capacity = -1, evictionFactor = 2, defaultMaxAge = -2, cleanupInterval = -1,
22 | evictionPolicy = "LRU");
23 | check cache.put("hi", "Ballerina");
24 | }
25 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample7/main.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org).
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/cache;
18 |
19 | configurable int capacity = 300;
20 | const decimal CACHE_CLEANUP_INTERVAL = 900.0;
21 |
22 | public function main() returns error? {
23 | cache:Cache cache = new(capacity = capacity , evictionFactor = 0.2, defaultMaxAge = 86400, cleanupInterval = CACHE_CLEANUP_INTERVAL);
24 | }
25 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample3/main.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 |
18 | import ballerina/cache;
19 |
20 | cache:CacheConfig config = {
21 | capacity:-1,
22 | evictionFactor: 2,
23 | defaultMaxAge: -2,
24 | cleanupInterval: -1,
25 | evictionPolicy: "LRU"
26 | };
27 |
28 | public function main() returns error? {
29 | cache:Cache cache = new(config);
30 | check cache.put("hi", "Ballerina");
31 | }
32 |
--------------------------------------------------------------------------------
/load-tests/order_management_service/scripts/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 | # Copyright 2021 WSO2 Inc. (http://wso2.org)
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | # ----------------------------------------------------------------------------
17 | # Execution script for ballerina performance tests
18 | # ----------------------------------------------------------------------------
19 | set -e
20 | source base-scenario.sh
21 |
22 | jmeter -n -t "$scriptsDir/"http-post-request.jmx -l "$resultsDir/"original.jtl -Jusers=10 -Jduration=1200 -Jhost=bal.perf.test -Jport=80 -Jprotocol=http -Jpath=serv $payload_flags
23 |
--------------------------------------------------------------------------------
/native/src/test/resources/testng.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample1/main.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/cache;
18 |
19 | public function main() returns error? {
20 |
21 | cache:CacheConfig config = {
22 | capacity:-1,
23 | evictionFactor: 2,
24 | defaultMaxAge: -2,
25 | cleanupInterval: -1,
26 | evictionPolicy: "LRU"
27 | };
28 | cache:Cache cache = new(config);
29 | check cache.put("hi", "Ballerina");
30 | }
31 |
--------------------------------------------------------------------------------
/ballerina/cache_errors.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2019 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | # Represents Cache related errors. This will be returned if an error occurred while doing any of the cache operations.
18 | public type Error distinct error;
19 |
20 | # Prepare the `error` as a `cache:Error`.
21 | #
22 | # + message - Error message
23 | # + return - Prepared `Error` instance
24 | isolated function prepareError(string message) returns Error {
25 | Error cacheError = error Error(message);
26 | return cacheError;
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/testng.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/native/spotbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheCompilerPlugin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package io.ballerina.stdlib.cache.compiler;
20 |
21 | import io.ballerina.projects.plugins.CompilerPlugin;
22 | import io.ballerina.projects.plugins.CompilerPluginContext;
23 |
24 | /**
25 | * Compiler plugin for Cache object.
26 | */
27 | public class CacheCompilerPlugin extends CompilerPlugin {
28 | @Override
29 | public void init(CompilerPluginContext compilerPluginContext) {
30 | compilerPluginContext.addCodeAnalyzer(new CacheCodeAnalyzer());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/diagnostics/sample4/main.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/cache;
18 |
19 | public type CacheConfig record {
20 | int capacity;
21 | float evictionFactor;
22 | };
23 |
24 | public isolated class HttpCache {
25 |
26 | final cache:Cache cache;
27 |
28 | public isolated function init(CacheConfig cacheConfig) {
29 | cache:CacheConfig config = {
30 | capacity: cacheConfig.capacity,
31 | evictionFactor: cacheConfig.evictionFactor,
32 | cleanupInterval: -1,
33 | evictionPolicy: "LRU"
34 | };
35 | self.cache = new cache:Cache(config);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/load-tests/order_management_service/src/resources/order_service/public.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDdzCCAl+gAwIBAgIEfP3e8zANBgkqhkiG9w0BAQsFADBkMQswCQYDVQQGEwJV
3 | UzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxDTALBgNVBAoT
4 | BFdTTzIxDTALBgNVBAsTBFdTTzIxEjAQBgNVBAMTCWxvY2FsaG9zdDAeFw0xNzEw
5 | MjQwNTQ3NThaFw0zNzEwMTkwNTQ3NThaMGQxCzAJBgNVBAYTAlVTMQswCQYDVQQI
6 | EwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzENMAsGA1UEChMEV1NPMjENMAsG
7 | A1UECxMEV1NPMjESMBAGA1UEAxMJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF
8 | AAOCAQ8AMIIBCgKCAQEAgVyi6fViVLiZKEnw59xzNi1lcYh6z9dZnug+F9gKqFIg
9 | mdcPe+qtS7gZc1jYTjWMCbx13sFLkZqNHeDUadpmtKo3TDduOl1sqM6cz3yXb6L3
10 | 4k/leh50mzIPNmaaXxd3vOQoK4OpkgO1n32mh6+tkp3sbHmfYqDQrkVK1tmYNtPJ
11 | ffSCLT+CuIhnJUJco7N0unax+ySZN67/AX++sJpqAhAIZJzrRi6ueN3RFCIxYDXS
12 | MvxrEmOdn4gOC0o1Ar9u5Bp9N52sqqGbN1x6jNKi3bfUj122Hu5e+Y9KOmfbchhQ
13 | il2P81cIi30VKgyDn5DeWEuDoYredk4+6qAZrxMw+wIDAQABozEwLzAOBgNVHQ8B
14 | Af8EBAMCBaAwHQYDVR0OBBYEFNmtrQ36j6tUGhKrfW9qWWE7KFzMMA0GCSqGSIb3
15 | DQEBCwUAA4IBAQAv3yOwgbtOu76eJMl1BCcgTFgaMUBZoUjK9Un6HGjKEgYz/YWS
16 | ZFlY/qH5rT01DWQevUZB626d5ZNdzSBZRlpsxbf9IE/ursNHwHx9ua6fB7yHUCzC
17 | 1ZMp1lvBHABi7wcA+5nbV6zQ7HDmBXFhJfbgH1iVmA1KcvDeBPSJ/scRGasZ5q2W
18 | 3IenDNrfPIUhD74tFiCiqNJO91qD/LO+++3XeZzfPh8NRKkiPX7dB8WJ3YNBuQAv
19 | gRWTISpSSXLmqMb+7MPQVgecsepZdk8CwkRLxh3RKPJMjigmCgyvkSaoDMKAYC3i
20 | YjfUTiJ57UeqoSl0IaOFJ0wfZRFh+UytlDZa
21 | -----END CERTIFICATE-----
22 |
--------------------------------------------------------------------------------
/.github/workflows/trigger-load-tests.yml:
--------------------------------------------------------------------------------
1 | name: Trigger Load Tests
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | tests:
7 | description: >
8 | List of test names. This needs to be filled only if you want to run a specific set of tests. Example: foo,bar
9 | required: false
10 | clusterName:
11 | description: 'Cluster name'
12 | default: 'cache-perf-cluster-test'
13 | required: false
14 | branch:
15 | description: 'Branch of the given repository'
16 | default: ''
17 | required: false
18 | schedule:
19 | - cron: '0 2 * * *'
20 |
21 | jobs:
22 | call_stdlib_trigger_load_test_workflow:
23 | name: Run StdLib Load Test Workflow
24 | if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
25 | uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@main
26 | with:
27 | repo_name: 'module-ballerina-cache'
28 | runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerina-cache/actions/artifacts'
29 | dispatch_type: 'cache-load-test'
30 | cluster_name: ${{ inputs.clusterName }}
31 | tests: ${{ inputs.tests }}
32 | branch: ${{ inputs.branch }}
33 | secrets:
34 | ballerina_bot_token: ${{ secrets.BALLERINA_BOT_TOKEN }}
35 |
--------------------------------------------------------------------------------
/native/src/main/java/io/ballerina/stdlib/cache/nativeimpl/concurrentlinkedhashmap/Weigher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package io.ballerina.stdlib.cache.nativeimpl.concurrentlinkedhashmap;
19 |
20 | /**
21 | * A class that can determine the weight of a value. The total weight threshold is used to
22 | * determine when an eviction is required.
23 | *
24 | * @param the type of values to weigh
25 | */
26 | interface Weigher {
27 |
28 | /**
29 | * Measures an object's weight to determine how many units of capacity that the value
30 | * consumes. A value must consume a minimum of one unit.
31 | *
32 | * @param value the object to weigh
33 | * @return the object's weight
34 | */
35 | int weightOf(V value);
36 | }
37 |
--------------------------------------------------------------------------------
/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/CacheCodeAnalyzer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package io.ballerina.stdlib.cache.compiler;
20 |
21 | import io.ballerina.compiler.syntax.tree.SyntaxKind;
22 | import io.ballerina.projects.plugins.CodeAnalysisContext;
23 | import io.ballerina.projects.plugins.CodeAnalyzer;
24 |
25 | import java.util.List;
26 |
27 | /**
28 | * Cache Code Analyzer.
29 | */
30 | public class CacheCodeAnalyzer extends CodeAnalyzer {
31 |
32 | @Override
33 | public void init(CodeAnalysisContext codeAnalysisContext) {
34 | codeAnalysisContext.addSyntaxNodeAnalysisTask(new CacheConfigValidator(),
35 | List.of(SyntaxKind.LOCAL_VAR_DECL, SyntaxKind.MODULE_VAR_DECL));
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/changelog.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 | This file contains all the notable changes done to the Ballerina Cache package through the releases.
3 |
4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6 |
7 | ## [unreleased]
8 | ### Fixed
9 | - [Fix the compilation failure when constants and configurables are used in cache config as included params](https://github.com/ballerina-platform/ballerina-library/issues/6036)
10 |
11 | ## [3.7.1] - 2024-01-11
12 |
13 | ### Fixed
14 | - [Fix the compilation failure when constants are used in cache config](https://github.com/ballerina-platform/ballerina-library/issues/5915)
15 |
16 | ## [2.1.0-beta.1] - 2021-06-02
17 |
18 | ### Added
19 | - [Introduced the compiler plugin to validate cache configurations](https://github.com/ballerina-platform/ballerina-standard-library/issues/1435)
20 |
21 | ### Changed
22 | - [API docs updated](https://github.com/ballerina-platform/ballerina-standard-library/issues/3463)
23 |
24 | ## [2.0.0-alpha5] - 2021-03-19
25 |
26 | ### Added
27 | - [Introduced the new configuration as “EvictionPolicy“ to set the eviction policy](https://github.com/ballerina-platform/ballerina-standard-library/issues/1027)
28 |
29 | ### Removed
30 | - [Remove the “AbstractEvictionPolicy” Object](https://github.com/ballerina-platform/ballerina-standard-library/issues/1027)
31 |
32 | ### Changed
33 | - Update for Time API changes
34 | - Update for Task API changes
--------------------------------------------------------------------------------
/.github/workflows/build-with-bal-test-graalvm.yml:
--------------------------------------------------------------------------------
1 | name: GraalVM Check
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | lang_tag:
7 | description: Branch/Release Tag of the Ballerina Lang
8 | required: true
9 | default: master
10 | lang_version:
11 | description: Ballerina Lang Version (If given ballerina lang buid will be skipped)
12 | required: false
13 | default: ''
14 | native_image_options:
15 | description: Default native-image options
16 | required: false
17 | default: ''
18 | schedule:
19 | - cron: '30 18 * * *'
20 | pull_request:
21 | branches:
22 | - master
23 | types: [opened, synchronize, reopened, labeled, unlabeled]
24 |
25 | concurrency:
26 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
27 | cancel-in-progress: true
28 |
29 | jobs:
30 | call_stdlib_workflow:
31 | name: Run StdLib Workflow
32 | if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
33 | uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main
34 | with:
35 | lang_tag: ${{ inputs.lang_tag }}
36 | lang_version: ${{ inputs.lang_version }}
37 | native_image_options: ${{ inputs.native_image_options }}
38 | additional_ubuntu_build_flags: '-x :cache-native:test -x :cache-compiler-plugin-tests:test'
39 | additional_windows_build_flags: '-x :cache-native:test -x :cache-compiler-plugin-tests:test'
40 |
--------------------------------------------------------------------------------
/compiler-plugin/src/main/java/io/ballerina/stdlib/cache/compiler/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package io.ballerina.stdlib.cache.compiler;
19 |
20 | /**
21 | * Constants used in compiler plugin.
22 | */
23 | public class Constants {
24 | public static final String BALLERINA = "ballerina";
25 | public static final String CACHE = "cache";
26 | public static final String CACHE_CONFIG = "CacheConfig";
27 |
28 | public static final String CAPACITY = "capacity";
29 | public static final String CLEAN_UP_INTERVAL = "cleanupInterval";
30 | public static final String EVICTION_FACTOR = "evictionFactor";
31 | public static final String EVICTION_POLICY = "evictionPolicy";
32 | public static final String DEFAULT_MAX_AGE = "defaultMaxAge";
33 | public static final String POLICY_VALUE = "cache:LRU";
34 | public static final String UNNECESSARY_CHARS_REGEX = "\"|\\n";
35 | }
36 |
--------------------------------------------------------------------------------
/.github/workflows/update_specs.yml:
--------------------------------------------------------------------------------
1 | name: Update Specifications
2 |
3 | env:
4 | SPEC_FOLDER_PATH: 'docs/spec'
5 |
6 | on:
7 | workflow_dispatch:
8 | push:
9 | branches:
10 | - master
11 | paths:
12 | - 'docs/spec/**'
13 |
14 | jobs:
15 | update_specs:
16 | name: Update Specifications
17 | if: github.repository_owner == 'ballerina-platform'
18 | runs-on: ubuntu-latest
19 |
20 | steps:
21 | - name: Checkout Repository
22 | uses: actions/checkout@v2
23 |
24 | - name: Get current date
25 | id: date
26 | run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
27 |
28 | - name: Get Repo Name
29 | id: repo_name
30 | run: |
31 | MODULE=${{ github.event.repository.name }}
32 | echo "::set-output name=short_name::${MODULE##*-}"
33 |
34 | - name: Trigger Workflow
35 | run: |
36 | curl --request POST \
37 | 'https://api.github.com/repos/ballerina-platform/ballerina-dev-website/dispatches' \
38 | -H 'Accept: application/vnd.github.v3+json' \
39 | -H 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \
40 | --data "{
41 | \"event_type\": \"update-stdlib-specs\",
42 | \"client_payload\": {
43 | \"module_name\": \"${{ github.event.repository.name }}\",
44 | \"short_name\": \"${{ steps.repo_name.outputs.short_name }}\",
45 | \"file_dir\": \"${{ github.event.repository.name }}/${{ env.SPEC_FOLDER_PATH }}\",
46 | \"release_date\": \"${{ steps.date.outputs.date }}\"
47 | }
48 | }"
49 |
--------------------------------------------------------------------------------
/native/src/main/java/io/ballerina/stdlib/cache/nativeimpl/concurrentlinkedhashmap/Linked.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package io.ballerina.stdlib.cache.nativeimpl.concurrentlinkedhashmap;
19 |
20 | /**
21 | * An element that is linked on the Deque.
22 | *
23 | * @param the type of elements held in this collection
24 | */
25 | interface Linked> {
26 |
27 | /**
28 | * Retrieves the previous element or null if either the element is unlinked
29 | * or the first element on the deque.
30 | */
31 | T getPrevious();
32 |
33 | /** Sets the previous element or null if there is no link. */
34 | void setPrevious(T prev);
35 |
36 | /**
37 | * Retrieves the next element or null if either the element is unlinked or
38 | * the last element on the deque.
39 | */
40 | T getNext();
41 |
42 | /** Sets the next element or null if there is no link. */
43 | void setNext(T next);
44 | }
45 |
--------------------------------------------------------------------------------
/native/src/main/java/io/ballerina/stdlib/cache/nativeimpl/concurrentlinkedhashmap/Weighers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package io.ballerina.stdlib.cache.nativeimpl.concurrentlinkedhashmap;
19 |
20 | /**
21 | * A common set of {@link Weigher} implementations.
22 | *
23 | */
24 | final class Weighers {
25 |
26 | private Weighers() {}
27 |
28 | /**
29 | * A weigher where a value has a weight of 1. A map bounded with this weigher
30 | * will evict when the number of key-value pairs exceeds the capacity.
31 | *
32 | * @return A weigher where a value takes one unit of capacity.
33 | */
34 | @SuppressWarnings("unchecked")
35 | public static Weigher singleton() {
36 | return (Weigher) SingletonWeigher.INSTANCE;
37 | }
38 |
39 | private enum SingletonWeigher implements Weigher