{"id":19991242,"url":"https://github.com/toolgood/ToolGood.AntiDuplication","last_synced_at":"2025-05-04T10:31:17.203Z","repository":{"id":38008825,"uuid":"179688153","full_name":"toolgood/ToolGood.AntiDuplication","owner":"toolgood","description":"当网络波动时，可防重复提交","archived":false,"fork":false,"pushed_at":"2022-12-08T05:29:14.000Z","size":67,"stargazers_count":42,"open_issues_count":1,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T13:52:39.921Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toolgood.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-05T13:37:20.000Z","updated_at":"2024-07-18T00:22:41.000Z","dependencies_parsed_at":"2023-01-24T12:30:23.690Z","dependency_job_id":null,"html_url":"https://github.com/toolgood/ToolGood.AntiDuplication","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolgood%2FToolGood.AntiDuplication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolgood%2FToolGood.AntiDuplication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolgood%2FToolGood.AntiDuplication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toolgood%2FToolGood.AntiDuplication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toolgood","download_url":"https://codeload.github.com/toolgood/ToolGood.AntiDuplication/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252320183,"owners_count":21729084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T04:51:40.785Z","updated_at":"2025-05-04T10:31:14.936Z","avatar_url":"https://github.com/toolgood.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"ToolGood.AntiDuplication\r\n===\r\n\r\n欢迎使用`ToolGood.AntiDuplication`！`ToolGood.AntiDuplication` 是一款轻量级防重复提交组件。\r\n\r\n\r\n### 快速上手\r\n\r\n```` csharp\r\n\tprivate readonly static AntiDupCache\u003cint, int\u003e antiDupCache = new AntiDupCache\u003cint, int\u003e(50, 1);\r\n\tprivate readonly static AntiDupQueue\u003cint, int\u003e antiDupQueue = new AntiDupQueue\u003cint, int\u003e(50);\r\n\tprivate readonly static DictCache\u003cint, int\u003e dictCache = new DictCache\u003cint, int\u003e();\r\n\r\n\tantiDupCache.GetOrAdd(key, () =\u003e {\r\n\t\t....\r\n\t\treturn val;\r\n\t});\r\n\r\n\tantiDupQueue.GetOrAdd(key, () =\u003e {\r\n\t\t....\r\n\t\treturn val;\r\n\t});\r\n\r\n\tdictCache.GetOrAdd(key, () =\u003e {\r\n\t\t....\r\n\t\treturn val;\r\n\t});\r\n\r\n`````\r\n\r\n注意：`AntiDupCache`、`AntiDupQueue`、`DictCache`类的`GetOrAdd`方法中的`key`不要设置为`null`，`key`为null时，不缓存值。\r\n\r\n注意：`DictCache`需要手动调用`Clear`方法清空缓存。\r\n\r\n\r\n\r\n\r\n### 性能：\r\n````\r\n----------------------- 测试缓存性能 从1到100 重复次数：10000 单位： ms -----------------------\r\n    并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\nAntiDupCache： 275  221  263  254  263  259  243  269  272  255  257  278\r\nAntiDupQueue： 114  119  122  142  143  136  144  148  142  168  173  166\r\n   DictCache： 109  117  120  138  139  127  145  150  160  161  160  193\r\n       Cache： 91   96   122  113  103  121  125  123  133  128  156  149\r\n\r\n----------------------- 仿线上环境  从1到1000  单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 1891 957  641  476  383  318  278  241  218  199  187  164\r\n  AntiDupCache： 1868 959  632  481  380  319  269  241  215  195  193  163\r\n  AntiDupQueue： 1897 947  629  477  383  321  273  241  212  195  187  162\r\n     DictCache： 1897 954  639  470  382  318  277  239  215  195  187  163\r\n         Cache： 1888 1897 1901 1871 1892 1879 1850 1845 1860 1830 1812 1909\r\n第二次普通并发： 1950 977  646  476  375  327  278  244  218  190  191  161\r\n\r\n----------------------- 开始  从1到100   重复次数：1 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 185  95   62   46   40   39   28   29   22   21   20   20\r\n  AntiDupCache： 188  93   64   45   39   39   28   28   22   20   18   22\r\n  AntiDupQueue： 190  93   61   47   37   36   29   29   22   19   18   23\r\n     DictCache： 186  95   64   46   37   37   29   30   19   19   18   21\r\n         Cache： 191  191  184  186  188  186  181  185  187  186  186  180\r\n第二次普通并发： 185  93   60   48   34   36   28   30   22   19   17   20\r\n\r\n----------------------- 开始  从1到100   重复次数：2 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 373  188  126  91   75   62   59   48   45   36   37   59\r\n  AntiDupCache： 187  96   63   48   37   34   29   26   23   19   18   24\r\n  AntiDupQueue： 191  95   63   47   38   33   29   25   20   17   18   23\r\n     DictCache： 190  96   65   47   39   32   28   22   23   19   18   23\r\n         Cache： 179  190  181  185  188  186  182  180  178  182  180  180\r\n第二次普通并发： 374  183  128  94   72   63   60   46   40   36   37   41\r\n\r\n----------------------- 开始  从1到100   重复次数：3 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 555  283  194  144  113  95   87   77   67   55   56   45\r\n  AntiDupCache： 187  94   64   46   39   34   27   28   23   18   18   16\r\n  AntiDupQueue： 181  92   66   45   37   38   30   29   24   20   18   14\r\n     DictCache： 187  95   67   47   38   32   29   23   22   19   18   15\r\n         Cache： 183  188  186  191  188  185  183  186  183  182  182  174\r\n第二次普通并发： 559  282  192  141  113  94   90   77   66   55   56   45\r\n\r\n----------------------- 开始  从1到100   重复次数：4 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 744  379  250  193  155  131  111  94   93   83   73   70\r\n  AntiDupCache： 188  95   65   42   40   34   29   25   22   19   18   19\r\n  AntiDupQueue： 193  93   66   44   41   34   30   26   20   18   20   20\r\n     DictCache： 187  96   65   47   37   31   28   26   21   20   19   19\r\n         Cache： 183  185  187  190  181  187  181  181  179  182  177  179\r\n第二次普通并发： 745  375  255  185  155  127  106  92   90   75   74   67\r\n\r\n----------------------- 开始  从1到100   重复次数：5 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 925  473  317  236  191  162  138  120  110  94   90   91\r\n  AntiDupCache： 189  94   65   48   37   35   29   26   21   19   18   19\r\n  AntiDupQueue： 193  93   65   47   37   34   28   29   23   21   18   20\r\n     DictCache： 194  95   68   49   39   35   31   25   22   22   18   19\r\n         Cache： 190  184  193  198  192  188  184  184  197  188  179  178\r\n第二次普通并发： 927  464  314  232  191  158  138  126  112  93   93   90\r\n\r\n----------------------- 开始  从1到100   重复次数：6 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 1124 566  380  281  224  190  162  141  138  112  112  95\r\n  AntiDupCache： 180  93   61   48   38   32   30   25   25   20   18   20\r\n  AntiDupQueue： 184  92   64   48   39   36   31   22   20   17   19   19\r\n     DictCache： 193  96   63   48   39   35   31   23   22   19   20   20\r\n         Cache： 188  190  185  188  184  189  179  188  176  180  186  181\r\n第二次普通并发： 1130 563  389  290  229  192  170  146  132  116  114  93\r\n\r\n----------------------- 开始  从1到100   重复次数：7 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 1312 667  446  330  270  225  190  255  162  134  135  122\r\n  AntiDupCache： 198  98   67   47   36   33   32   30   22   17   17   20\r\n  AntiDupQueue： 188  92   63   45   39   37   31   29   23   19   19   19\r\n     DictCache： 189  93   62   48   39   33   30   25   22   20   18   20\r\n         Cache： 192  199  196  194  190  193  199  196  192  184  187  180\r\n第二次普通并发： 1306 668  430  330  269  230  190  165  154  129  128  116\r\n\r\n----------------------- 开始  从1到100   重复次数：8 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 1507 759  500  384  300  257  220  189  179  153  148  140\r\n  AntiDupCache： 187  95   65   47   42   35   29   27   23   20   18   20\r\n  AntiDupQueue： 184  99   63   44   41   37   30   27   23   21   18   19\r\n     DictCache： 191  96   66   48   38   35   29   25   22   20   18   18\r\n         Cache： 191  187  190  188  188  181  183  181  183  182  180  184\r\n第二次普通并发： 1499 755  512  382  305  252  218  186  179  151  150  138\r\n\r\n----------------------- 开始  从1到100   重复次数：9 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 1694 839  564  429  341  286  255  215  193  169  167  143\r\n  AntiDupCache： 186  94   67   51   39   37   29   26   24   20   20   18\r\n  AntiDupQueue： 198  89   63   51   40   36   30   29   25   19   20   17\r\n     DictCache： 183  97   65   45   36   33   31   28   23   22   18   17\r\n         Cache： 182  189  191  189  182  176  185  184  179  175  177  176\r\n第二次普通并发： 1682 843  573  430  345  277  251  218  193  171  168  147\r\n\r\n----------------------- 开始  从1到100   重复次数：10 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 1863 929  634  474  378  321  274  236  212  189  188  160\r\n  AntiDupCache： 190  95   66   47   39   33   30   26   23   21   19   19\r\n  AntiDupQueue： 184  94   61   49   39   32   31   23   23   20   17   19\r\n     DictCache： 186  96   66   46   39   33   28   24   23   20   18   21\r\n         Cache： 184  188  191  188  188  181  182  176  186  189  180  177\r\n第二次普通并发： 1873 939  639  470  375  323  274  240  214  188  190  164\r\n\r\n----------------------- 开始  从1到100   重复次数：11 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 2051 1039 698  518  421  349  298  274  233  211  188  185\r\n  AntiDupCache： 187  95   63   49   42   37   28   29   23   20   22   21\r\n  AntiDupQueue： 187  92   68   48   36   35   31   27   25   19   21   20\r\n     DictCache： 199  99   65   48   37   34   31   28   24   19   20   19\r\n         Cache： 190  193  197  186  192  193  194  199  194  191  190  191\r\n第二次普通并发： 2083 1041 695  521  423  351  299  268  239  213  188  182\r\n\r\n----------------------- 开始  从1到100   重复次数：12 单位： ms -----------------------\r\n      并发数量： 1    2    3    4    5    6    7    8    9    10   11   12\r\n      普通并发： 2241 1132 757  574  460  379  332  286  258  234  206  186\r\n  AntiDupCache： 182  91   63   46   38   34   29   28   24   22   22   20\r\n  AntiDupQueue： 183  93   63   47   39   35   29   26   27   21   21   17\r\n     DictCache： 185  93   64   46   38   32   29   26   26   20   21   19\r\n         Cache： 182  187  190  184  185  187  185  184  176  182  187  175\r\n第二次普通并发： 2242 1135 757  561  453  376  326  283  252  227  208  192\r\n\r\n----------------------- 结束 -----------------------\r\n\r\n\r\n````\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolgood%2FToolGood.AntiDuplication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoolgood%2FToolGood.AntiDuplication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoolgood%2FToolGood.AntiDuplication/lists"}